update method

T update(
  1. T cb(
    1. T state
    )
)

Calls a function with the current state and assign the result as 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.state).state = ref.read(provider.state).state + 1;

we can do:

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

Implementation

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