首页 文章

如何在flutter webview中打开应用程序链接?

提问于
浏览
0

在Flutter中,我使用flutter webview plugin来启动一个网址:

flutterWebviewPlugin.launch(url)

要么

WebviewScaffold(
  url: url,
  appBar: new AppBar(title: Text(title), actions: [
    new IconButton(
      icon: const Icon(Icons.share),
      onPressed: () => Share.share(url),
    )
  ]),
  withZoom: true,
  withLocalStorage: true,
  withJavascript: true,
);

但是,如果打开的网页中的任何链接是应用程序链接,例如:fb:// profile,我将获得net :: ERR_UNKNOWN_URL_SCHEME .

在android中,我发现解决方案是覆盖here中提到的shouldOverrideUrlLoading,但是我该怎么办呢?

3 回答

  • 0

    看起来你可以使用这个插件实现你所需要的:https://pub.dartlang.org/packages/flutter_web_view

    听取你的重定向:

    flutterWebView.listenForRedirect("fb://profile", true);
    

    获取 Value 使用:

    flutterWebView.onRedirect.listen((url) {
       flutterWebView.dismiss();
        //now you have the url
     });
    

    获得网址后,您可以使用此包https://pub.dartlang.org/packages/url_launcher

  • 0

    你可以使用web插件

    @override
     Widget build(BuildContext context) {
       String url = widget.url;
       return Scaffold(
        body: Center(
        child : WebviewScaffold(
          url: "https://google.com",
          appBar: new AppBar(
            title: new Text(widget.title),
          ),
          withZoom: true,
          withLocalStorage: true,
         )
       ),
     );
    }
    
  • 0

    这可能不是你想要的,但我会建议一个带有指向AppStore直接页面链接的按钮 .

    这些AppStore链接可以使用Apple提供的this one等网站进行 .

    这是android提供的一个click me

    它只是一个链接,可以立即打开App Store而不是进入Web视图 .

相关问题