onState method
void
onState({
- void onInitial()?,
- void onLoading()?,
- void onSuccess(
- S value
- void onError(
- E error
Implementation
void onState({
void Function()? onInitial,
void Function()? onLoading,
void Function(S value)? onSuccess,
void Function(E error)? onError,
}) {
if (onInitial != null) {
on<InitialState<E, S>>((value) {
onInitial();
});
}
if (onLoading != null) {
on<LoadingState<E, S>>((value) {
onLoading();
});
}
if (onSuccess != null) {
on<SuccessState<E, S>>((value) {
onSuccess(value.data);
});
}
if (onError != null) {
on<ErrorState<E, S>>((value) {
onError(value.error);
});
}
}