remove method

CandidType? remove(
  1. Object? key
)
inherited

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

CandidType? remove(Object? key) {
    late int k;
    if (key is String) {
        k = candid_text_hash(key);
    } else
    if (key is int) {
        if (key >= pow(2,32)) {
            throw Exception('candid fieldtype-id as an int needs to be < 2^32. "An id value must be smaller than 2^32 and no id may occur twice in the same record type." ');
        }
        k = key;
    }
    else {
        throw Exception('must pass in a String or an int as a fieldtype-id');
    }
    return _map.remove(k);
}