-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Is it possible to call native function in html, just like Android's JavascriptInterface and JsBridge #59
Comments
Yes, sure! |
That is great, haha |
Feature added now on the new version 1.1.0. <script>
// you need to wait and listen the JavaScript event flutterInAppBrowserPlatformReady
window.addEventListener("flutterInAppBrowserPlatformReady", function(event) {
console.log("ready");
// then you can call the window.flutter_inappbrowser.callHandler() method.
// callHandler() returns a Promise that you can use to get data from Dart side.
window.flutter_inappbrowser.callHandler('handlerFoo').then(function(result) {
console.log(result, typeof result);
console.log(JSON.stringify(result), result.bar);
});
window.flutter_inappbrowser.callHandler('handlerFooWithArgs', 1, true, ['bar', 5], {foo: 'baz'}).then(function(result) {
console.log(result, typeof result);
console.log(JSON.stringify(result));
});
});
</script> Instead, on the // Inject JavaScript that will receive data back from Flutter
webView.injectScriptCode("""
window.flutter_inappbrowser.callHandler('test', 'Text from Javascript').then(function(result) {
console.log(result);
});
"""); |
Yes, This is a good way to call the Dart method. Thanks for informing this new feature. And how about Dart calls the JS method? Has this problem been solved in the new version? |
Happy news! Happy news! I successfully got the response from JS using the code you provided, even though it still report the error log. |
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. |
There are many onClick events in html that require native responses.
Is it possible to implement that?
The text was updated successfully, but these errors were encountered: