mutate method

Future<void> mutate (void mutation())

Notify the underlying state that the internal data has changed.

Whenever you mutate the state's data, do it within a function that you pass to mutate:

state.mutate(() { state.value = newValue });

The provided callback is immediately called synchronously. It must not return a future (the callback cannot be async), since then it would be unclear when the state was actually being set.

Implementation

Future<void> mutate(void Function() mutation) async {
  try {
    preMutate();

    mutation();
    _subject.add(this);

    postMutate();
  } catch(e, st) {
    this.onError(e, st);
  }
}