JavaScriptMessage class
A message that was sent by JavaScript code running in a WebView.
Platform specific implementations can add additional fields by extending this class and providing a factory method that takes the JavaScriptMessage as a parameter.
This example demonstrates how to extend the JavaScriptMessage to provide additional platform specific parameters.
When extending JavaScriptMessage additional parameters should always
accept null or have a default value to prevent breaking changes.
@immutable
class WKWebViewScriptMessage extends JavaScriptMessage {
WKWebViewScriptMessage._(
JavaScriptMessage javaScriptMessage,
this.extraData,
) : super(
message: javaScriptMessage.message,
sourceUrl: javaScriptMessage.sourceUrl,
sourceOrigin: javaScriptMessage.sourceOrigin,
isMainFrame: javaScriptMessage.isMainFrame,
);
factory WKWebViewScriptMessage.fromJavaScriptMessage(
JavaScriptMessage javaScriptMessage, {
String? extraData,
}) {
return WKWebViewScriptMessage._(
javaScriptMessage,
extraData,
);
}
final String? extraData;
}
- Annotations
Constructors
- JavaScriptMessage({required String message, String? sourceUrl, String? sourceOrigin, bool? isMainFrame})
-
Creates a new JavaScript message object.
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isMainFrame → bool?
-
Whether the main frame's document sent the message, when the platform
reports it;
nullotherwise.final - message → String
-
The contents of the message that was sent by the JavaScript code.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sourceOrigin → String?
-
The browser security origin of the sending document, when available.
final
- sourceUrl → String?
-
The URL of the document that sent the message, or
nullwhen unavailable.final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited