setMessageHandler method

  1. @override
void setMessageHandler(
  1. String channel,
  2. MessageHandler? handler
)
override

Set a callback for receiving messages from the platform plugins on the given channel, without decoding them.

The given callback will replace the currently registered callback for that channel, if any. To remove the handler, pass null as the handler argument.

The handler's return value, if non-null, is sent as a response, unencoded.

Implementation

@override
void setMessageHandler(String channel, MessageHandler? handler) {
  if (handler == null) {
    _inboundHandlers.remove(channel);
    delegate.setMessageHandler(channel, null);
  } else {
    _inboundHandlers[channel] = handler; // used to handle fake messages sent via handlePlatformMessage
    delegate.setMessageHandler(channel, handler); // used to handle real messages from the engine
  }
}