-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Return data from JavaScriptHandler #46
Labels
enhancement
New feature or request
Comments
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);
});
"""); |
This was referenced Jul 6, 2020
Closed
Closed
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. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Is it possible to return data from the Flutter JavaScript Handler, back to the Javascript that called it? See example below
I tried messing around a bit with the example to get it to work, but was ultimately unable to do so. I had to update the JavaScriptHandlerCallback to return a Future<dynamic> and change the JavaScriptBridgeInterface._callHandler to return a String, but that still didn't solve it. The main issue seemed to be that there can be a third parameter for invokeMethod("onCallJsHandler", ...) that could get the response from Flutter, but because it is asynchronous the javascript code is no longer waiting around for a response.
I don't know enough about how Flutter's MethodCall works for getting data to and from native code.
Any help would be greatly appreciated. Thanks!
The text was updated successfully, but these errors were encountered: