handlePlatformMessage method

Future<void> handlePlatformMessage (String channel, ByteData data, PlatformMessageResponseCallback callback)

Calls the handler registered for the given channel.

Typically called by ServicesBinding to handle platform messages received from Window.onPlatformMessage.

To register a handler for a given message channel, see setMessageHandler.

Implementation

static Future<void> handlePlatformMessage(
      String channel, ByteData data, ui.PlatformMessageResponseCallback callback) async {
  ByteData response;
  try {
    final _MessageHandler handler = _handlers[channel];
    if (handler != null)
      response = await handler(data);
  } catch (exception, stack) {
    FlutterError.reportError(FlutterErrorDetails(
      exception: exception,
      stack: stack,
      library: 'services library',
      context: 'during a platform message callback',
    ));
  } finally {
    callback(response);
  }
}