How to open app links in flutter webview?

前端 未结 3 662
谎友^
谎友^ 2021-02-03 12:45

In Flutter, I use the flutter webview plugin to launch a url like:

flutterWebviewPlugin.launch(url)

or

WebviewScaffold(
  url:          


        
3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-03 13:37

    You can use webview_flutter in pub.dev Packages

    WebView(
            initialUrl: 'https://my.url.com',
            javascriptMode: JavascriptMode.unrestricted,
            navigationDelegate: (NavigationRequest request)
            {
              if (request.url.startsWith('https://my.redirect.url.com'))
              {
                print('blocking navigation to $request}');
                _launchURL('https://my.redirect.url.com');
                return NavigationDecision.prevent;
              }
    
              print('allowing navigation to $request');
              return NavigationDecision.navigate;
            },
          )
    

    And you can launch url with url_launcher in pub.dev Packages

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

提交回复
热议问题