onReceiveCreateNewInstancePair method Null safety

Object? onReceiveCreateNewInstancePair(
  1. String channelName,
  2. PairedInstance pairedInstance,
  3. List<Object?> arguments,
  4. {required bool owner}

Create and store a new instance pair for a type channel.

Throw an assertion error if pairedInstance has already been added. Otherwise, it returns the paired object.


Object? onReceiveCreateNewInstancePair(
  String channelName,
  PairedInstance pairedInstance,
  List<Object?> arguments, {
  required bool owner,
}) {
    getPairedObject(pairedInstance) == null,
    'An object with `PairedInstance` has already been created.',

  final TypeChannelHandler? handler = getChannelHandler(channelName);
  if (handler == null) {
    throw ArgumentError(
      'A `TypeChannelHandler` must be set for channel of: $channelName.',

  final Object instance = handler.createInstance(
    converter.convertPairedInstances(instanceManager, arguments)!
        as List<Object?>,

  assert(!isPaired(instance), '`$instance` has already been paired.');

    instance: instance,
    instanceId: pairedInstance.instanceId,
    owner: owner,
  return instance;