postWebMessage method Null safety

Future<void> postWebMessage(
  1. {required WebMessage message,
  2. Uri? targetOrigin}
)

Post a message to main frame. The embedded application can restrict the messages to a certain target origin. See HTML5 spec for how target origin can be used.

A target origin can be set as a wildcard ("*"). However this is not recommended.

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

NOTE: On iOS, it is implemented using JavaScript.

Supported Platforms/Implementations:

Implementation

Future<void> postWebMessage(
    {required WebMessage message, Uri? targetOrigin}) async {
  if (targetOrigin == null) {
    targetOrigin = Uri.parse("");
  }
  Map<String, dynamic> args = <String, dynamic>{};
  args.putIfAbsent('message', () => message.toMap());
  args.putIfAbsent('targetOrigin', () => targetOrigin.toString());
  await _channel.invokeMethod('postWebMessage', args);
}