reset method
Resets the value to the originalValue.
If T
is a class with properties, changing the properties directly on the object
instead of updating this ActiveType 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
final age = ActiveType<int>(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) {
activeController.notifyActivities([
ActiveStateChanged(
_originalValue,
currentValue,
typeName: typeName,
)
]);
}
}