toId method Null safety

  1. @protected
String? toId(
  1. Object? object,
  2. String groupName
)

Returns a unique id for object that will remain live at least until disposeGroup is called on groupName.

Implementation

@protected
String? toId(Object? object, String groupName) {
  if (object == null) {
    return null;
  }

  final Set<_InspectorReferenceData> group = _groups.putIfAbsent(groupName, () => Set<_InspectorReferenceData>.identity());
  String? id = _objectToId[object];
  _InspectorReferenceData referenceData;
  if (id == null) {
    id = 'inspector-$_nextId';
    _nextId += 1;
    _objectToId[object] = id;
    referenceData = _InspectorReferenceData(object);
    _idToReferenceData[id] = referenceData;
    group.add(referenceData);
  } else {
    referenceData = _idToReferenceData[id]!;
    if (group.add(referenceData)) {
      referenceData.count += 1;
    }
  }
  return id;
}