update method

T update(
  1. T cb(
    1. T 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

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