remove method
Removes key and its associated value, if present, from the map.
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}
Implementation
@override
dynamic remove(Object? key) {
if (raw is! Map) return null;
final newindexMeta = getMetamethod('__newindex');
if (newindexMeta != null) {
final oldValue = this[key];
callMetamethod('__newindex', [this, _wrapRuntimeValue(key), _nilValue()]);
return oldValue;
}
final storageKey = _computeStorageKey(key);
var value = (raw as Map).remove(storageKey);
final gcLocal = GCAccess.fromValue(this);
if (gcLocal != null) {
MemoryCredits.instance.recalculate(this);
}
return value == null ? null : _wrapRuntimeValue(value);
}