getOrDefault method
V?
getOrDefault(
- K key,
- V? defaultValue
Returns the value associated with the given key
,
or defaultValue
if the key does not exists.
Example:
final map = {'name', 'John', 'email': 'john@example.com'};
print(getOrDefault('name', 'Unknown')); // Output: John
print(getOrDefault('email', 'NA')); // Output: john@example.com
print(getOrDefault('age', 'undefined')); // Output: undefined
Implementation
V? getOrDefault(K key, V? defaultValue) =>
containsKey(key) ? this[key]! : defaultValue;