updateAll method

  1. @override
void updateAll(
  1. _Updater<K, V> update, {
  2. bool notifyListeners = true,
})
override

Updates all values.

Iterates over all entries in the map and updates them with the result of invoking update.

final terrestrial = <int, String>{1: 'Mercury', 2: 'Venus', 3: 'Earth'};
terrestrial.updateAll((key, value) => value.toUpperCase());
print(terrestrial); // {1: MERCURY, 2: VENUS, 3: EARTH}

Implementation

@override
void updateAll(_Updater<K, V> update, {bool notifyListeners = true}) {
  if (notifyListeners) {
    final events = <K, V>{};
    value.forEach((key, value) {
      final newValue = update(key, value);
      if (value != newValue) {
        this.value[key] = newValue;
        events.addAll(<K, V>{key: newValue});
        notifyChangeListeners(
            CollectionChangeEvent(CollectionEventType.update, key, newValue));
      }
    });

    if (events.isNotEmpty) {
      notifyEventListeners(
          CollectionEvent<K, V>(CollectionEventType.update, events));
      this.notifyListeners(value);
    }
  } else {
    value.updateAll(update);
  }
}