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 use event onLoadResourceCustomScheme #365

Closed
rathanak opened this issue May 27, 2020 · 2 comments
Closed

How to use event onLoadResourceCustomScheme #365

rathanak opened this issue May 27, 2020 · 2 comments

Comments

@rathanak
Copy link

Hi ,
I got stuck with onLoadResourceCustomScheme event , how to declare it in webview option ? and how to call to use it in event ?

@pichillilorenzo
Copy link
Owner

Here is an example.

You need first declare what custom schemes you need to intercept using the resourceCustomSchemes option:

initialOptions: InAppWebViewGroupOptions(
    crossPlatform: InAppWebViewOptions(
      debuggingEnabled: true,
      resourceCustomSchemes: ["my-special-custom-scheme"]
    )
),

Then, in the onLoadResourceCustomScheme event you can intercept it and return your CustomSchemeResponse:

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

In my example, I'm simply reading an asset file from the test_assets/ folder using rootBundle (import 'package:flutter/services.dart';) and return the new asset to the WebView.

In my test HTML I have:

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

that will be intercepted by the onLoadResourceCustomScheme event.

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 11, 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