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 PlatformWebViewCreationParams.onLoadStop is fired, otherwise the PlatformWebMessageChannel won't work.

Officially Supported Platforms/Implementations:

Use the PlatformInAppWebViewController.isMethodSupported method to check if this method is supported at runtime.

Implementation

Future<WebMessageChannel?> createWebMessageChannel() async {
  final webMessagePlatform = await platform.createWebMessageChannel();
  if (webMessagePlatform == null) {
    return null;
  }
  return WebMessageChannel.fromPlatform(platform: webMessagePlatform);
}