maybeWhen<R extends Object?> method
R
maybeWhen<R extends Object?>({
- required R orElse(),
- R initialState()?,
- R loadingState(
- double? progress
- R succeedState(
- T successObject
- R failedState(
- String? failureMessage,
- dynamic exception,
- VoidCallback? retryCallback
Implementation
R maybeWhen<R extends Object?>({
required R Function() orElse,
R Function()? initialState,
R Function(double? progress)? loadingState,
R Function(T successObject)? succeedState,
R Function(String? failureMessage, dynamic exception, VoidCallback? retryCallback)? failedState,
}) {
final FourStates<T> state = this;
return switch (state) {
InitialState<T>() => initialState == null ? orElse() : initialState(),
LoadingState<T>() => loadingState == null ? orElse() : loadingState(state.progress),
SucceedState<T>() => succeedState == null ? orElse() : succeedState(state.successObject),
FailedState<T>() => failedState == null
? orElse()
: failedState(state.failureMessage, state.exceptionObject, state.retryCallback),
};
}