在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,但是我该如何应对?
答案 0 :(得分:2)
您可以在pub.dev程序包中使用 webview_flutter
Windows 10
您可以在pub.dev程序包中使用 url_launcher 启动url
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;
},
)
答案 1 :(得分:0)
看起来您可以使用此插件实现所需的功能:https://pub.dartlang.org/packages/flutter_web_view
收听您的重定向:
flutterWebView.listenForRedirect("fb://profile", true);
使用以下方法获取值:
flutterWebView.onRedirect.listen((url) {
flutterWebView.dismiss();
//now you have the url
});
获得网址后,您可以使用此软件包https://pub.dartlang.org/packages/url_launcher
答案 2 :(得分:0)
您可以使用网络插件
@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,
)
),
);
}
答案 3 :(得分:0)
我在下面复制的 net::ERR_UNKNOWN_URL_SCHEME
错误 here 有一个解决方案:
在您的 application
标签中添加以下行:
android:usesCleartextTraffic="true"
如下图:
<application
....
android:usesCleartextTraffic="true"
....>
如果您有网络安全配置,例如:android:networkSecurityConfig="@xml/network_security_config"
无需如上所示将明文流量设置为 true,而是使用以下代码:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
....
....
</domain-config>
<base-config cleartextTrafficPermitted="false"/>
</network-security-config>
将 cleartextTrafficPermitted
设置为 true