ViewStateListener<T, B extends BlocBase<ViewState>> constructor

ViewStateListener<T, B extends BlocBase<ViewState>>({
  1. Key? key,
  2. B? bloc,
  3. BlocListenerCondition<ViewState>? listenWhen,
  4. LoadingCallback? onLoading,
  5. RefreshingCallback<T>? onRefreshing,
  6. SuccessCallback<T>? onSuccess,
  7. EmptyCallback? onEmpty,
  8. ErrorCallback? onError,
  9. Widget? child,
})

Implementation

ViewStateListener({
  super.key,
  super.bloc,
  super.listenWhen,
  LoadingCallback? onLoading,
  RefreshingCallback<T>? onRefreshing,
  SuccessCallback<T>? onSuccess,
  EmptyCallback? onEmpty,
  ErrorCallback? onError,
  super.child,
}) : super(
        listener: (BuildContext context, ViewState state) {
          if (state is Loading) {
            onLoading?.call(context);
          } else if (state is Refreshing<T>) {
            onRefreshing?.call(context, state.data);
          } else if (state is Success<T>) {
            onSuccess?.call(context, state.data);
          } else if (state is Empty) {
            onEmpty?.call(context);
          } else if (state is Failure) {
            onError?.call(context, state.error);
          }
        },
      );