registerMessageHandler method Null safety

void registerMessageHandler()

Registers the registrar's message handler (handlePlatformMessage) with the engine, so that plugin messages are correctly dispatched to the relevant registered plugin.

Only one handler can be registered at a time. Calling this method a second time silently unregisters any previously-registered handler and replaces it with the handler from this object.

This method uses a function called webOnlySetPluginHandler in the dart:ui library. That function is only available when compiling for the web.

Implementation

void registerMessageHandler() {
  // The `ui.webOnlySetPluginHandler` function below is only defined in the Web dart:ui.
  // ignore: undefined_function, avoid_dynamic_calls
  ui.webOnlySetPluginHandler(handleFrameworkMessage);
}