update method
- @protected
- FutureOr<
State> cb(- State
- FutureOr<
State> onError(- Object err,
- StackTrace stackTrace
inherited
A function to update state from its previous value, while abstracting loading/error cases for state.
If state was in error state, the callback will not be invoked and instead
the error will be returned. Alternatively, onError
can specified to
gracefully handle error states.
See also:
Implementation
@protected
Future<State> update(
FutureOr<State> Function(State) cb, {
FutureOr<State> Function(Object err, StackTrace stackTrace)? onError,
}) async {
// TODO cancel on rebuild?
final newState = await future.then(cb, onError: onError);
state = AsyncData<State>(newState);
return newState;
}