addEntries method

  1. @override
void addEntries(
  1. Iterable<MapEntry<K, V>> newEntries, {
  2. bool notifyListeners = true,
})
override

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

If a key of newEntries is already in this map, the corresponding value is overwritten.

The operation is equivalent to doing this[entry.key] = entry.value for each MapEntry of the iterable.

final planets = <int, String>{1: 'Mercury', 2: 'Venus',
  3: 'Earth', 4: 'Mars'};
final gasGiants = <int, String>{5: 'Jupiter', 6: 'Saturn'};
final iceGiants = <int, String>{7: 'Uranus', 8: 'Neptune'};
planets.addEntries(gasGiants.entries);
planets.addEntries(iceGiants.entries);
print(planets);
// {1: Mercury, 2: Venus, 3: Earth, 4: Mars, 5: Jupiter, 6: Saturn,
//  7: Uranus, 8: Neptune}

Implementation

@override
void addEntries(
  Iterable<MapEntry<K, V>> newEntries, {
  bool notifyListeners = true,
}) {
  value.addEntries(newEntries);

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

      for (var entry in newEntries) {
        events.addAll(<K, V>{entry.key: entry.value});

        notifyChangeListeners(CollectionChangeEvent(
            CollectionEventType.addition, entry.key, entry.value));
      }

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

    this.notifyListeners(value);
  }
}