clear method
Removes all entries from the map.
After this, the map is empty.
Note: To avoid O(N) memory allocations, the generated CurrentStateChanged event
does not contain a snapshot of the map's items prior to being cleared. If you
need to preserve the previous items, you must explicitly pass capturePrevious: true
or cache them yourself.
final planets = CurrentMapProperty<int, String>{1: 'Mercury', 2: 'Venus', 3: 'Earth'};
planets.clear(); // {}
Implementation
void clear({bool notifyChanges = true, bool capturePrevious = false}) {
final previousValue = capturePrevious ? Map<K, V>.from(_value) : null;
final stateChangedEvent = CurrentStateChanged(
<K, V>{},
previousValue,
propertyName: propertyName,
sourceHashCode: sourceHashCode,
);
_value.clear();
if (notifyChanges) {
viewModel.notifyChanges([stateChangedEvent]);
}
}