convertInstances method

  1. @override
Object? convertInstances(
  1. InstanceManager manager,
  2. Object? object
)
override

Converts objects to PairedInstances with ids stored in manager.

Conversions:

  • Objects paired in a TypeChannelMessenger are converted to their paired PairedInstance.
  • Lists are converted to List<Object?> and this method is applied to each value within the list.
  • Maps are converted to Map<Object?, Object?> and this method is applied to each key and each value.

Implementation

@override
Object? convertInstances(InstanceManager manager, Object? object) {
  if (object == null) {
    return null;
  } else if (manager.containsInstance(object)) {
    return PairedInstance(manager.getInstanceId(object)!);
  } else if (object is List) {
    return object.map<Object?>((_) => convertInstances(manager, _)).toList();
  } else if (object is Map) {
    return Map<Object?, Object?>.fromIterables(
      object.keys.map<Object?>((_) => convertInstances(manager, _)),
      object.values.map<Object?>((_) => convertInstances(manager, _)),
    );
  }

  return object;
}