map<R> method
R
map<R>({
- required R onLoading(),
- required R onDone(
- T? data
- required R onError(
- E? error
- required R onInit(),
Declare methods base on fetchingStatus
all state methods are required
return type R
need to be the same on all methods
Implementation
R map<R>({
required R Function() onLoading,
required R Function(T? data) onDone,
required R Function(E? error) onError,
required R Function() onInit,
}) {
switch (fetchingStatus) {
case FetchingStatus.init:
return onInit();
case FetchingStatus.loading:
return onLoading();
case FetchingStatus.done:
return onDone(data);
case FetchingStatus.error:
return onError(error);
}
}