addIf method
Adds an entry to the map if the predicate f
is satisfied.
Example:
var map = {1: 'a', 2: 'b'};
map.addIf((key, value) => key > 2, 3, 'c');
// map = {1: 'a', 2: 'b', 3: 'c'}
Implementation
Map<K, V> addIf(bool Function(K key, V value) f, K key, V value) {
if (f(key, value)) {
addEntries([MapEntry(key, value)]);
}
return this;
}