setMultiple method Null safety
- List<
Map< settersEmpireProperty, dynamic> >
Set multiple EmpireProperty values, but only trigger a single state change
The setters
is a list of maps, where the keys are the properties you want to set, and the values are the new
values for each property. Each map in the list must contain exactly one key/value pair.
Usage
late final EmpireProperty<String> name;
late final EmpireProperty<int> age;
setMultiple([
{name: 'Doug'},
{age: 45},
]);
Implementation
void setMultiple(List<Map<EmpireProperty, dynamic>> setters) {
final List<EmpireStateChanged> changes = [];
for (var setter in setters) {
assert(setter.keys.length == 1,
'Each setter item must contain exactly one key/value pair.');
final property = setter.keys.first;
final previousValue = property.value;
final nextValue = setter.values.first;
changes.add(EmpireStateChanged(nextValue, previousValue,
propertyName: property.propertyName));
property(nextValue, notifyChange: false);
}
notifyChanges(changes);
}