addIfNotNull method
Adds an item into the map if the value is not null
and the key does not exist.
Example:
Map<String, int>? map = {"a": 1};
map = map.addIfNotNull("b", 2);
print(map); // {a: 1, b: 2}
map = map.addIfNotNull("b", null);
print(map); // {a: 1, b: 2} (unchanged)
Implementation
Map<K, V>? addIfNotNull(K key, V value) {
if (value != null) this?.putIfAbsent(key, () => value);
return this;
}