update method

StateT update(
  1. StateT cb(
    1. StateT state
    )
)

Calls a function with the current state and assigns the result as the new state.

This allows simplifying the syntax for updating the state when the update depends on the previous state, such that rather than:

ref.read(provider.notifier).state = ref.read(provider.notifier).state + 1;

we can do:

ref.read(provider.notifier).update((state) => state + 1);

Implementation

StateT update(StateT Function(StateT state) cb) => state = cb(state);