getEntry method

MapEntry<K, V>? getEntry(
  1. Object? key
)

Returns the MapEntry for key, or null if not found or invalid.

If key is null, not of type K, or if the weak key or value was garbage-collected, the entry is removed and null is returned.

Implementation

MapEntry<K, V>? getEntry(Object? key) {
  if (key == null || key is! K) return null;

  var k = _EntryKey<K, V>(key);
  // ignore: collection_methods_unrelated_type
  var e = _map[k];
  if (e == null) return null;

  var eKey = e.target;
  var eValue = e.payload;

  if (eKey == null || eValue == null) {
    _map.remove(e);
    _onRemoveEntry(e);
    ++_unpurgedCount;
    return null;
  }

  return MapEntry(eKey, eValue);
}