Flutter 在AppWebView中颤振-在浏览器中打开其他网站地址
我在使用Webview时通过下面的代码实现了这一点Flutter 在AppWebView中颤振-在浏览器中打开其他网站地址,flutter,flutter-inappwebview,Flutter,Flutter Inappwebview,我在使用Webview时通过下面的代码实现了这一点 navigationDelegate: (NavigationRequest request) { if (request.url.startsWith('https://google.com/')) { print('allowing navigation to $request'); return NavigationDeci
navigationDelegate: (NavigationRequest request) {
if (request.url.startsWith('https://google.com/')) {
print('allowing navigation to $request');
return NavigationDecision.navigate;
} else {
print('Opening Default Browser');
launchURL(request.url); // to open browser
return NavigationDecision.prevent;
}
},
但是当我使用inappwebview时,上面的代码不起作用。使用Inappwebview时,我应该如何在浏览器中打开外部网址
InAppWebView:您可以对InAppWebView使用
shouldOverrideUrlLoading:()
shouldOverrideUrlLoading: (controller, shouldOverrideUrlLoadingRequest) async {
var url = shouldOverrideUrlLoadingRequest.url;
var uri = Uri.parse(url);
if ((uri.toString()).startsWith('https://google.com')) {
return ShouldOverrideUrlLoadingAction.ALLOW;
}else {
launchURL(uri.toString());
return ShouldOverrideUrlLoadingAction.CANCEL;
}
},