when<T> method
T
when<T>({
- required T loading(),
- required T data(
- S data
- required T error(),
override
Pattern matching for async state.
loading
is called if the state is loading.
data
is called if the state contains data.
error
is called if the state contains an error.
Returns the result of the matching callback.
Implementation
@override
T when<T>({
required T Function() loading,
required T Function(S data) data,
required T Function(ErrorState e) error,
}) {
switch (_status) {
case AsyncStatus.loading:
return loading();
case AsyncStatus.error:
return error(errorState!);
case AsyncStatus.data:
return data(this.data as S);
}
}