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

ViewStateBuilder<T, B extends BlocBase<ViewState<T>>>({
  1. Key? key,
  2. B? bloc,
  3. InitialBuilder? onReady,
  4. LoadingBuilder? onLoading,
  5. RefreshingBuilder<T>? onRefreshing,
  6. SuccessBuilder<T>? onSuccess,
  7. EmptyBuilder? onEmpty,
  8. ErrorBuilder? onError,
  9. BlocBuilderCondition<ViewState<T>>? buildWhen,
})

Implementation

ViewStateBuilder({
  super.key,
  super.bloc,
  InitialBuilder? onReady,
  LoadingBuilder? onLoading,
  RefreshingBuilder<T>? onRefreshing,
  SuccessBuilder<T>? onSuccess,
  EmptyBuilder? onEmpty,
  ErrorBuilder? onError,
  super.buildWhen,
}) : super(
        builder: (BuildContext context, ViewState<T> state) {
          const empty = SizedBox.shrink();
          return switch (state) {
            Initial() => onReady?.call(context) ?? empty,
            Loading() => onLoading?.call(context) ?? empty,
            Refreshing<T>(data: final data) =>
              onRefreshing?.call(context, data) ?? empty,
            Success<T>(data: final data) =>
              onSuccess?.call(context, data) ?? empty,
            Empty() => onEmpty?.call(context) ?? empty,
            Failure(error: final error) =>
              onError?.call(context, error) ?? empty,
          };
        },
      );