operator [] method
Get corresponded values, which associated with key
.
Unlike Map will return Null when no value paired with key
,
it throws InvalidDictionaryKeyError.
In additions, the key
must be String type, applying other types
will throw DictionaryKeyTypeMismatchError.
Implementation
@override
V operator [](Object? key) {
_checkKeyType(key);
if (!containsKey(key)) {
throw InvalidDictionaryKeyError(key as String,
"No value found that it associated with the given key.");
}
return entries.singleWhere((element) => element.key == key).value;
}