onState method

void onState({
  1. void onInitial()?,
  2. void onLoading()?,
  3. void onSuccess(
    1. S value
    )?,
  4. void onError(
    1. 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);
    });
  }
}