I achieved this thanks to the code below while using Webview
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;
}
},
But when I used inappwebview, the above code didn't work. What should I do to open external web addresses in the browser when using Inappwebview?
InAppWebView: https://pub.dev/packages/flutter_inappwebview
You can use shouldOverrideUrlLoading:() for InAppWebView.
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;
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With