useValueChanged<T, R> function
R?
useValueChanged<T, R>(
- T value,
- R? valueChange(
- T oldValue,
- R? oldResult
Watches a value and triggers a callback whenever the value changed.
useValueChanged takes a valueChange
callback and calls it whenever value
changed.
valueChange
will not be called on the first useValueChanged call.
useValueChanged can also be used to interpolate
Whenever useValueChanged is called with a different value
, calls valueChange
.
The value returned by useValueChanged is the latest returned value of valueChange
or null
.
The following example calls AnimationController.forward whenever color
changes
AnimationController controller;
Color color;
useValueChanged(color, (_, __) {
controller.forward();
});
Implementation
R? useValueChanged<T, R>(
T value,
R? Function(T oldValue, R? oldResult) valueChange,
) {
return use(_ValueChangedHook(value, valueChange));
}