addAll method

  1. @override
void addAll(
  1. Map<K, V> other, {
  2. bool notifyListeners = true,
})
override

Adds all key/value pairs of other to this map.

If a key of other is already in this map, its value is overwritten.

The operation is equivalent to doing this[key] = value for each key and associated value in other. It iterates over other, which must therefore not change during the iteration.

final planets = <int, String>{1: 'Mercury', 2: 'Earth'};
planets.addAll({5: 'Jupiter', 6: 'Saturn'});
print(planets); // {1: Mercury, 2: Earth, 5: Jupiter, 6: Saturn}

Implementation

@override
void addAll(Map<K, V> other, {bool notifyListeners = true}) {
  value.addAll(other);

  if (notifyListeners) {
    if (hasEvent || hasChangeEvent) {
      final events = <K, V>{};

      other.forEach((key, value) {
        events.addAll(<K, V>{key: value});
        notifyChangeListeners(
            CollectionChangeEvent(CollectionEventType.addition, key, value));
      });

      if (events.isNotEmpty) {
        notifyEventListeners(
            CollectionEvent<K, V>(CollectionEventType.addition, events));
      }
    }

    this.notifyListeners(value);
  }
}