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

ViewStateBuilder<T, B extends BlocBase<ViewState<T>>>({
  1. Key? key,
  2. B? bloc,
  3. @Deprecated('This builder will be removed. Use "initial" instead.') InitialBuilder? onReady,
  4. InitialBuilder? initial,
  5. @Deprecated('This builder will be removed. Use "loading" instead.') LoadingBuilder? onLoading,
  6. LoadingBuilder? loading,
  7. @Deprecated('This builder removed. Use "refreshing" instead.') RefreshingBuilder<T>? onRefreshing,
  8. RefreshingBuilder<T>? refreshing,
  9. @Deprecated('This builder removed. Use "data" instead.') SuccessBuilder<T>? onSuccess,
  10. DataBuilder<T>? data,
  11. @Deprecated('This builder removed. Use "none" instead.') EmptyBuilder? onEmpty,
  12. EmptyBuilder? empty,
  13. @Deprecated('This builder removed. Use "none" instead.') ErrorBuilder? onError,
  14. ErrorBuilder? error,
  15. BlocBuilderCondition<ViewState<T>>? buildWhen,
})

Implementation

ViewStateBuilder({
  super.key,
  super.bloc,
  @Deprecated('This builder will be removed. Use "initial" instead.')
  InitialBuilder? onReady,
  InitialBuilder? initial,
  @Deprecated('This builder will be removed. Use "loading" instead.')
  LoadingBuilder? onLoading,
  LoadingBuilder? loading,
  @Deprecated('This builder removed. Use "refreshing" instead.')
  RefreshingBuilder<T>? onRefreshing,
  RefreshingBuilder<T>? refreshing,
  @Deprecated('This builder removed. Use "data" instead.')
  SuccessBuilder<T>? onSuccess,
  DataBuilder<T>? data,
  @Deprecated('This builder removed. Use "none" instead.')
  EmptyBuilder? onEmpty,
  EmptyBuilder? empty,
  @Deprecated('This builder removed. Use "none" instead.')
  ErrorBuilder? onError,
  ErrorBuilder? error,
  super.buildWhen,
})  : assert(
        !(onReady != null && initial != null),
        'The onReady and initial builders should NOT be used together. The onReady builder is deprecated and can be safely removed.',
      ),
      assert(
        !(onLoading != null && loading != null),
        'The onLoading and loading builders should NOT be used together. The onLoading builder is deprecated and can be safely removed.',
      ),
      assert(
        !(onRefreshing != null && refreshing != null),
        'The onRefreshing and refreshing builders should NOT be used together. The onRefreshing builder is deprecated and can be safely removed.',
      ),
      assert(
        !(onSuccess != null && data != null),
        'The onSuccess and data builders should NOT be used together. The onSuccess builder is deprecated and can be safely removed.',
      ),
      assert(
        !(onEmpty != null && empty != null),
        'The onEmpty and empty builders should NOT be used together. The onEmpty builder is deprecated and can be safely removed.',
      ),
      assert(
        !(onError != null && error != null),
        'The onEmpty and error builders should NOT be used together. The onError builder is deprecated and can be safely removed.',
      ),
      super(
        builder: (BuildContext context, ViewState<T> state) {
          const none = SizedBox.shrink();
          return switch (state) {
            Initial<T>() =>
              (initial?.call(context) ?? onReady?.call(context)) ?? none,
            Loading<T>() =>
              (loading?.call(context) ?? onLoading?.call(context)) ?? none,
            Refreshing<T>(value: final value) =>
              (refreshing?.call(context, value) ??
                      onRefreshing?.call(context, value)) ??
                  none,
            Data<T>(value: final value) => (data?.call(context, value) ??
                    onSuccess?.call(context, value)) ??
                none,
            Empty<T>() =>
              (empty?.call(context) ?? onEmpty?.call(context)) ?? none,
            Failure<T>(error: final value) => (error?.call(context, value) ??
                    onError?.call(context, value)) ??
                none,
          };
        },
      );