Flutter WebView Does Not open external links

151 views Asked by At

so I´ve been working in a webview project for my php code, the thing is, I have some redirects inside the app, like email, phone and others.

The problema is it doesnt seen to work been trying to use url_launcher, but even with this and a code that seens right, Im stil get the error net::ERR_UNKNOWN_URL_SCHEME.

i have seen this topic Flutter Webview - Opening External Links in Browser or Window but mostly its deprecated, and the new docs doesnt do match for webview

anyway thats the part of my code that is supposed to make it work

class MyNavigationDelegate extends NavigationDelegate {
Future\<Object\> shouldOverrideUrlLoading(
WebViewController controller, NavigationRequest navigation) async {
var uri = Uri.parse(navigation.url);

if (uri.scheme == 'mailto') {
final email = uri.path.substring(1);
final mailtoUrl = 'mailto:$email';
await launchUrl(Uri.parse(mailtoUrl));
return NavigationDecision.prevent;
} else if (uri.scheme == 'tel') {`your text`
final tel = uri.path.substring(1);
final telUrl = 'tel:$tel';
await launchUrl(Uri.parse(telUrl));
return NavigationDecision.prevent;
}

return false;`
}

}

class \_MyHomePageState extends State\<MyHomePage\> {
late final WebViewController controller;`

@override`
void initState() {
controller = WebViewController();
controller.setJavaScriptMode(JavaScriptMode.unrestricted);
controller.setNavigationDelegate(MyNavigationDelegate());
controller.loadRequest(Uri.parse(" my url "));
addFileSelectionListener();
super.initState();
}\
1

There are 1 answers

0
Ashok Kmr On

you wrongly formatted code block , re-post the code with right format