useValueChanged<T, R> function

R useValueChanged <T, R>(
  1. T value,
  2. R valueChange(
    1. T oldValue,
    2. R oldResult
    )
)

Watches a value and calls 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 diffent 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));
}