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