remove method Null safety

V? remove(
  1. Object? key


Returns the value associated with key before it was removed. Returns null if key was not in the map.

Note that some maps allow null as a value, so a returned null value doesn't always mean that the key was absent.

final terrestrial = <int, String>{1: 'Mercury', 2: 'Venus', 3: 'Earth'};
final removedValue = terrestrial.remove(2); // Venus
print(terrestrial); // {1: Mercury, 3: Earth}


V? remove(Object? key) {
  if (!_validKey(key)) return null;
  _SplayTreeMapNode<K, V>? mapRoot = _remove(key as dynamic);
  if (mapRoot != null) return mapRoot.value;
  return null;