How to allow mailto and tel URL schemes in WebView Flutter?

孤街浪徒 提交于 2020-05-28 04:24:24

问题


I am developing WebApp in Flutter but when I click on tel:987654321 or mailto: links going page Not Found, To open the default app in mobile I am using url_launcher dependency But in the background when I click WebView also run the same link and go to page not found.

How to handle this task?


回答1:


navigationDelegate: (NavigationRequest request) {
  if(request.url.contains("mailto:")) {
    launch(request.url);
    return NavigationDecision.prevent;
  }
  else if (request.url.contains("tel:")) {
    launch(request.url);
    return NavigationDecision.prevent;
  }
},



回答2:


Add some details, need url_launcher plugin

import 'package:webview_flutter/webview_flutter.dart';
import 'package:url_launcher/url_launcher.dart';

  _launchURL(url) async {
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }

in Widget-build ...

WebView(
        initialUrl: 'http://example.com',
        navigationDelegate: (NavigationRequest request) {
          if (request.url.contains("mailto:")) {
            _launchURL(request.url);
            return NavigationDecision.prevent;
          } else if (request.url.contains("tel:")) {
            _launchURL(request.url);
            return NavigationDecision.prevent;
          }
          return NavigationDecision.navigate;
        },
)



来源:https://stackoverflow.com/questions/56421218/how-to-allow-mailto-and-tel-url-schemes-in-webview-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!