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

后端 未结 2 1014
星月不相逢
星月不相逢 2021-01-15 00:00

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 u

相关标签:
2条回答
  • 2021-01-15 00:27
    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;
      }
    },
    
    0 讨论(0)
  • 2021-01-15 00:27

    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;
            },
    )
    
    
    0 讨论(0)
提交回复
热议问题