reset method Null safety
- {bool notifyChange = true}
Resets the value to what it was initialized with.
If T
is a class with properties, changing the properties directly on the object
instead of updating this EmpireProperty with a new instance of T
with the updated values will
prevent reset from performing as expected. Tracking the original value is done by reference
internally.
Usage
late final EmpireProperty<int> age = createProperty(10); //age.value is 10
age(20); //age.value is 20
age(25); //age.value is 25
age.reset(); //age.value is back to 10. Triggers UI rebuild or...
age.reset(notifyChange: false); //age.value is back to 10 but UI does not rebuild
Implementation
void reset({bool notifyChange = true}) {
final currentValue = _value;
_value = _originalValue;
if (notifyChange) {
_viewModel.notifyChanges([
EmpireStateChanged(
_originalValue,
currentValue,
propertyName: propertyName,
)
]);
}
}