Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link handling #43

Open
wkethman opened this issue Mar 4, 2018 · 19 comments
Open

Link handling #43

wkethman opened this issue Mar 4, 2018 · 19 comments

Comments

@wkethman
Copy link

wkethman commented Mar 4, 2018

Implementing the plugin as shown:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      routes: {
        "/": (_) => new WebviewScaffold(
          url: "http://wckethman.com/htree/my-app/www/index.html",
          withJavascript: true,
        )
      },
    );
  }
}
This works fine but when clicking on tel: links "net::ERR_UNKNOWN_URL_SCHEME" thrown

Any suggestions?

@shinriyo
Copy link

shinriyo commented Mar 4, 2018

@wkethman You mean

You replaced from

routes: {
  "/": (_) => new WebviewScaffold(
  url: "http://wckethman.com/htree/my-app/www/index.html",
  withJavascript: true,
)

to

like this?

routes: {
  "/": (_) => new WebviewScaffold(
  tel: "000-000-000",
  withJavascript: true,
)

I guess it doesn't support tel:.

If you append feature for tel:, author may accept your pull-request.

https://github.com/dart-flitter/flutter_webview_plugin/blob/b41c311a9562f770df52d8a61b5ea96c0a1a41b8/ios/Classes/FlutterWebviewPlugin.m#L99

@lejard-h
Copy link
Collaborator

Not supported yet.

Have not done that yet, but we should probably be able to catch that kind of call from the webview and call url_launcher

@alexmdavis
Copy link

The url_launcher approach works for me, except the Android webview also renders the ERR_UNKNOWN_URL_SCHEME error. I'd also need to interrupt loading; something like #14.

@sameerbakre
Copy link

sameerbakre commented Oct 22, 2018

do we have any way to handle error page on android yet? I can redirect to previous url after error. However it still shows the error which is not a good user experience.

@chintooflutter
Copy link

is this issue resolved or pending? i am facing the same problem.

Also not working when I click to whatsapp share button. It is opening in google play store.

@mohdkhmais
Copy link

having the same issue when clicking on tel link, any solutions so far ?

@grungebuddy
Copy link

having the same issue when clicking on tel link, any solutions so far ?

Here is a solution to disable navigation for tel and mailto for now:

https://stackoverflow.com/questions/56421218/how-to-allow-mailto-and-tel-url-schemes-in-webview-flutter

@wooldridgetm
Copy link

meh, just listen to the onUrlChanged stream to detect when the url is changing & has mail/tel/http(s). If so, then invoke goBack() on the WebViewPlugin instance & then use url_launcher to open the link. something like this...

_subscription = webViewPlugin.onUrlChanged.listen((String url) async {
      print("navigating to...$url");
      if (url.startsWith("mailto") || url.startsWith("tel") || url.startsWith("http") || url.startsWith("https"))
      {
        await webViewPlugin.stopLoading();
        await webViewPlugin.goBack();
        if (await canLaunch(url))
        {
           await launch(url);
           return;
        }
        print("couldn't launch $url");
      }
    });

@TimothySealy
Copy link

I've used a slightly different approach. For my use case I only needed to override the telephone links. I've used the invalidUrlRegex parameter of the WebviewScaffold to suppress navigation to tel: links:

WebviewScaffold(
   url: url,
   invalidUrlRegex: '^tel:',
);

I've used url_launcher to actually load the tel: links. In order to do so I listen to the state changed (onUrlChanged will not work because the navigation is suppressed for tel: links):

StreamSubscription<WebViewStateChanged> _onStateChanged;
_onStateChanged = flutterWebviewPlugin.onStateChanged.listen((WebViewStateChanged state) async {
  if (mounted) {
    if (state.url.startsWith('tel:') && state.type == WebViewState.abortLoad) {
      if (await canLaunch(state.url)) {
        await launch(state.url);
      }
    }
  }
});

Note that the state.type == WebViewState.abortLoad is not really required and you could combine the inner two if statements for brevity.

Also the tel: links load fine on iOS (also after this implementation), this is basically a work around for Android.

@mulenatni
Copy link

choose file is not working on flutter web app......call works fine thank you for your help

@djks74
Copy link

djks74 commented Sep 19, 2021

meh, just listen to the onUrlChanged stream to detect when the url is changing & has mail/tel/http(s). If so, then invoke goBack() on the WebViewPlugin instance & then use url_launcher to open the link. something like this...

_subscription = webViewPlugin.onUrlChanged.listen((String url) async {
      print("navigating to...$url");
      if (url.startsWith("mailto") || url.startsWith("tel") || url.startsWith("http") || url.startsWith("https"))
      {
        await webViewPlugin.stopLoading();
        await webViewPlugin.goBack();
        if (await canLaunch(url))
        {
           await launch(url);
           return;
        }
        print("couldn't launch $url");
      }
    });

Hi @wooldridgetm,
could you please share full example code for this?

I have problem and dont know how or where to put this code on the webview script.

I really appreciate.

@soukainader
Copy link

@djks74 please did you find a solution

@jishnumadhavan
Copy link

@djks74 please did you find a solution

if u have solution please share

@soukainader
Copy link

@djks74 please did you find a solution

if u have solution please share

yes please I really need it in my project

@djks74
Copy link

djks74 commented Feb 11, 2022

You mean for choose file and geolocation?
Im using this https://pub.dev/packages/flutter_webview_pro

Its working perfectly.

but if you want the navigation link working, better using https://pub.dev/packages/webview_flutter with launcURL

WebView(
onPageStarted: (String url) {
onUrlChange(url);
},
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
navigationDelegate: (NavigationRequest request) {
if (request.url.contains("uber")) {
_launchURL(request.url);
return NavigationDecision.prevent;
} else if (request.url.contains("tel:")) {
_launchURL(request.url);
return NavigationDecision.prevent;
} else if (request.url.contains("https://wa.me/")) {
_launchURL(request.url);
return NavigationDecision.prevent;
} else if (request.url.contains("mailto:")) {
_launchURL(request.url);
} else if (request.url.contains("market://")) {
return NavigationDecision.prevent;
}

                  return NavigationDecision.navigate;
                },

_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
}

@soukainader
Copy link

You mean for choose file and geolocation? Im using this https://pub.dev/packages/flutter_webview_pro

Its working perfectly.

but if you want the navigation link working, better using https://pub.dev/packages/webview_flutter with launcURL

WebView( onPageStarted: (String url) { onUrlChange(url); }, initialUrl: url, javascriptMode: JavascriptMode.unrestricted, navigationDelegate: (NavigationRequest request) { if (request.url.contains("uber")) { _launchURL(request.url); return NavigationDecision.prevent; } else if (request.url.contains("tel:")) { _launchURL(request.url); return NavigationDecision.prevent; } else if (request.url.contains("https://wa.me/")) { _launchURL(request.url); return NavigationDecision.prevent; } else if (request.url.contains("mailto:")) { _launchURL(request.url); } else if (request.url.contains("market://")) { return NavigationDecision.prevent; }

                  return NavigationDecision.navigate;
                },

_launchURL(String url) async { if (await canLaunch(url)) { await launch(url); } else { throw 'Could not launch $url'; } } }

@djks74 thank you so much, please do you have any idea how to check connexion in webview flutter. thank you in advance

@djks74
Copy link

djks74 commented Feb 11, 2022

Can you please describe what connection you mean? in flutter to phone to see debug?

@soukainader
Copy link

Can you please describe what connection you mean? in flutter to phone to see debug?

No I mean to replace WEB PAGE NO AVAILABLE with my customize page if I lost the connexion and reload it if I'm connected again.

@Mane-Mt
Copy link

Mane-Mt commented Feb 12, 2022

You mean for choose file and geolocation? Im using this https://pub.dev/packages/flutter_webview_pro

Its working perfectly.

but if you want the navigation link working, better using https://pub.dev/packages/webview_flutter with launcURL

WebView( onPageStarted: (String url) { onUrlChange(url); }, initialUrl: url, javascriptMode: JavascriptMode.unrestricted, navigationDelegate: (NavigationRequest request) { if (request.url.contains("uber")) { _launchURL(request.url); return NavigationDecision.prevent; } else if (request.url.contains("tel:")) { _launchURL(request.url); return NavigationDecision.prevent; } else if (request.url.contains("https://wa.me/")) { _launchURL(request.url); return NavigationDecision.prevent; } else if (request.url.contains("mailto:")) { _launchURL(request.url); } else if (request.url.contains("market://")) { return NavigationDecision.prevent; }

                  return NavigationDecision.navigate;
                },

_launchURL(String url) async { if (await canLaunch(url)) { await launch(url); } else { throw 'Could not launch $url'; } } }

@djks74 please can you share with us your solution (the complete code) with flutter_webview_plugin because in my case I can't, unfortunately, change to webview_flutter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests