updateAll method Null safety

void updateAll(
  1. V update(
    1. K key,
    2. V value
    ),
  2. {bool notifyChanges = true}
)

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

void updateAll(V Function(K key, V value) update,
    {bool notifyChanges = true}) {
  final stateChangedEvents = <EmpireStateChanged<V>>[];

  _value.updateAll((key, value) {
    final previousValue = value;
    final updatedValue = update(key, value);
    stateChangedEvents.add(EmpireStateChanged.updateMapEntry(
      key,
      previousValue,
      updatedValue,
      propertyName: propertyName,
    ));
    return updatedValue;
  });

  if (notifyChanges) {
    _viewModel.notifyChanges(stateChangedEvents);
  }
}