callAsyncJavaScript method
- required String functionBody,
- Map<
String, dynamic> arguments = const <String, dynamic>{}, - ContentWorld? contentWorld,
Executes the specified string as an asynchronous JavaScript function.
functionBody
is the JavaScript string to use as the function body.
This method treats the string as an anonymous JavaScript function body and calls it with the named arguments in the arguments parameter.
arguments
is a Map
of the arguments to pass to the function call.
Each key in the Map
corresponds to the name of an argument in the functionBody
string,
and the value of that key is the value to use during the evaluation of the code.
Supported value types can be found in the official Flutter docs:
Platform channel data types support and codecs,
except for Uint8List, Int32List, Int64List, and Float64List that should be converted into a List.
All items in a List
or Map
must also be one of the supported types.
contentWorld
, on iOS, it represents the namespace in which to evaluate the JavaScript source
code.
Instead, on Android, it will run the source
code into an iframe.
This parameter doesn’t apply to changes you make to the underlying web content, such as the document’s DOM structure.
Those changes remain visible to all scripts, regardless of which content world you specify.
For more information about content worlds, see ContentWorld.
Available on iOS 14.3+.
NOTE: This method shouldn't be called in the PlatformWebViewCreationParams.onWebViewCreated or PlatformWebViewCreationParams.onLoadStart events,
because, in these events, the WebView
is not ready to handle it yet.
Instead, you should call this method, for example, inside the PlatformWebViewCreationParams.onLoadStop event or in any other events
where you know the page is ready "enough".
NOTE for iOS: available only on iOS 10.3+.
NOTE for Android: available only on Android 21+.
Officially Supported Platforms/Implementations:
- Android native WebView
- iOS (Official API - WKWebView.callAsyncJavaScript)
- MacOS (Official API - WKWebView.callAsyncJavaScript)
- Windows
Implementation
Future<CallAsyncJavaScriptResult?> callAsyncJavaScript(
{required String functionBody,
Map<String, dynamic> arguments = const <String, dynamic>{},
ContentWorld? contentWorld}) =>
platform.callAsyncJavaScript(
functionBody: functionBody,
arguments: arguments,
contentWorld: contentWorld);