operator [] method

CandidType? operator [](
  1. dynamic key
)
inherited

The value for the given key, or null if key is not in the map.

Some maps allow null as a value. For those maps, a lookup using this operator cannot distinguish between a key not being in the map, and the key being there with a null value. Methods like containsKey or putIfAbsent can be used if the distinction is important.

Implementation

CandidType? operator [](dynamic key) { // String or int
    late int k;
    if (key is String) {
        k = candid_text_hash(key);
    } else
    if (key is int) {
        k = key;
    } else {
        throw Exception('must pass in either a String or an int to a fieldtype lookup');
    }
    return _map[k];
}