when<TReturn> method
TReturn
when<TReturn>({
- required TReturn onState(
- S state
- TReturn onLoading(
- bool isLoading
- TReturn onError(
- dynamic error
inherited
Represents a value of one of three mapped possibilities.
EXAMPLE:
int result = store.when<int>(
onState: (state) => state,
onLoading: () => 0,
onError: (error) => -1,
);
Implementation
TReturn when<TReturn>({
required TReturn Function(State state) onState,
TReturn Function(bool isLoading)? onLoading,
TReturn Function(dynamic error)? onError,
}) {
if (triple.event == TripleEvent.loading && onLoading != null && triple.isLoading) {
return onLoading(triple.isLoading);
} else if (triple.event == TripleEvent.error && onError != null) {
return onError(triple.error);
} else {
return onState(triple.state);
}
}