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(javaScriptMessage.message);

  factory WKWebViewScriptMessage.fromJavaScripMessage(
    JavaScriptMessage javaScripMessage, {
    String? extraData,
  }) {
    return WKWebViewScriptMessage._(
      javaScriptMessage,
      extraData: extraData,
    );
  }

  final String? extraData;
}
Annotations

Constructors

JavaScriptMessage({required String message})
Creates a new JavaScript message object.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
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

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