load method
Wrapper for a user defined loading logic that handles state setting
How it works:
- If the status is already set to ActionStatus.ongoing it returns
immediately, otherwise ActionStatus.ongoing status is set
along with the
initialData
(if provided) - User provided
body
function is executed - Upon completion the Outcome.data is set (if provided) along
with the final status determined by the Outcome constructor:
- Outcome.finished sets ActionStatus.done (default if no value is returned)
- Outcome.failed sets ActionStatus.failed
- Outcome.canceled sets ActionStatus.canceled
If anything is thrown from body
a ActionStatus.failed
status is set and the details are forwarded to onError
Implementation
@protected
Stream<StatefulState<Data>> load({
required FutureOr<Outcome<Data>?> Function() body,
Data? initialData,
}) async* {
if (state.beingLoaded) return;
yield* execute(
state: state,
type: ActionType.loading,
body: body,
onError: onError,
initialData: initialData,
);
}