push method

void push(
  1. String name,
  2. ByteData? data,
  3. PlatformMessageResponseCallback callback
)

Adds a message (data) to the named channel buffer (name).

The callback argument is a closure that, when called, will send messages back to the plugin.

If a message overflows the channel, and the channel has not been configured to expect overflow, then, in debug mode, a message will be printed to the console warning about the overflow.

Channel names cannot contain the U+0000 NULL character, because they are passed through APIs that use null-terminated strings.

Implementation

void push(String name, ByteData? data, PlatformMessageResponseCallback callback) {
  assert(!name.contains('\u0000'), 'Channel names must not contain U+0000 NULL characters.');
  final _Channel channel = _channels.putIfAbsent(name, () => _Channel());
  if (channel.push(_StoredMessage(data, callback))) {
    _printDebug(
      'A message on the $name channel was discarded before it could be handled.\n'
      'This happens when a plugin sends messages to the framework side before the '
      'framework has had an opportunity to register a listener. See the ChannelBuffers '
      'API documentation for details on how to configure the channel to expect more '
      'messages, or to expect messages to get discarded:\n'
      '  https://api.flutter.dev/flutter/dart-ui/ChannelBuffers-class.html\n'
      'The capacity of the $name channel is ${channel._capacity} message${channel._capacity != 1 ? 's' : ''}.',
    );
  }
}