createWebMessageChannel method

Future<WebMessageChannel?> createWebMessageChannel()

Creates a message channel to communicate with JavaScript and returns the message channel with ports that represent the endpoints of this message channel. The HTML5 message channel functionality is described here.

The returned message channels are entangled and already in started state.

This method should be called when the page is loaded, for example, when the WebView.onLoadStop is fired, otherwise the WebMessageChannel won't work.

NOTE for Android native WebView: This method should only be called if AndroidWebViewFeature.isFeatureSupported returns true for AndroidWebViewFeature.CREATE_WEB_MESSAGE_CHANNEL.

NOTE: On iOS, it is implemented using JavaScript.

Supported Platforms/Implementations:

Implementation

Future<WebMessageChannel?> createWebMessageChannel() async {
  Map<String, dynamic> args = <String, dynamic>{};
  Map<String, dynamic>? result =
      (await _channel.invokeMethod('createWebMessageChannel', args))
          ?.cast<String, dynamic>();
  return WebMessageChannel.fromMap(result);
}