mutate method
Executes the provided closure function, then notifies the state of a mutation.
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
void mutate(void Function() mutation) {
dynamic result = mutation() as dynamic;
if (result is Future) {
print('[WARNING] The closure function passed to mutate was marked as asynchronous or ' +
'returned a Future. The state cannot guarantee that the mutation will have completed ' +
'before the state is accessed by stream subscribers.');
}
publishMutation();
}