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

How to open to new schema? #188

Closed
tankchuen opened this issue Nov 9, 2019 · 2 comments
Closed

How to open to new schema? #188

tankchuen opened this issue Nov 9, 2019 · 2 comments

Comments

@tankchuen
Copy link

I use addthis plugin inside webview, when click share to social media will hit net:ERR_UNKNOWN_URL_SCHEME

i'm add these to my code still not working

initialOptions: {
     'resourceCustomSchemes': ["fb-messenger","tg","whatsapp"]
}

Is any where can fixed this? Thank you

WhatsApp Image 2019-11-09 at 1 45 13 PM

@pichillilorenzo
Copy link
Owner

resourceCustomSchemes option is used by the onLoadResourceCustomScheme event to intercept resource requests with custom scheme. For example in your html you have something like this:

 <img src="my-special-custom-scheme://images/flutter-logo.svg" alt="flutter logo">

So, in the initialOptions you would have:

initialOptions: InAppWebViewWidgetOptions(
    inAppWebViewOptions: InAppWebViewOptions(
        resourceCustomSchemes: ["my-special-custom-scheme"],
    )
)       

and the event handler could be something like this:

onLoadResourceCustomScheme: (InAppWebViewController controller, String scheme, String url) async {
  if (scheme == "my-special-custom-scheme") {
    var bytes = await rootBundle.load("assets/" + url.replaceFirst("my-special-custom-scheme://", "", 0));
    var response = new CustomSchemeResponse(bytes.buffer.asUint8List(), "image/svg+xml", contentEnconding: "utf-8");
    return response;
  }
  return null;
},

Instead, in your case you want to handle custom schemes that are not about resources like images, etc. So, in this case, you need to set the InAppWebViewOptions.useShouldOverrideUrlLoading option to true and to use shouldOverrideUrlLoading event:

shouldOverrideUrlLoading: (InAppWebViewController controller, String url) {
  if (url.startsWith("whatsapp://")) {
    // Open WhatsApp app
  } else if (url.startsWith("foo://")) {
    // check for other apps ...
  }
},

If you want to open an app like WhatsApp, you can use my other plugin flutter_appavailability.

However, you are using the 2.0 flutter_inappbrowser version that is not published yet. I need to finish the new documentation and create at least some tests before publishing it. Of course, you can use it at your own risk for now.

This was referenced Jul 6, 2020
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants