defaultBuilder<D extends DataState, E> function

Widget Function(BuildContext, BlocState) defaultBuilder<D extends DataState, E>({
  1. Widget onLoading(
    1. BuildContext context
    )?,
  2. required Widget onData(
    1. BuildContext context,
    2. D state
    ),
  3. Widget onError(
    1. BuildContext context,
    2. ErrorState<E> state
    )?,
  4. Widget otherwise(
    1. BuildContext context
    )?,
})

T = Type of state of Bloc in use D = Type of Data expected when you get Data E = Type of Data expected in Error

Implementation

Widget Function(BuildContext, BlocState)
    defaultBuilder<D extends DataState, E>({
  Widget Function(BuildContext context)? onLoading,
  required Widget Function(BuildContext context, D state) onData,
  Widget Function(BuildContext context, ErrorState<E> state)? onError,
  Widget Function(BuildContext context)? otherwise,
}) =>
        (context, state) {
          if (state is LoadingState) {
            return (onLoading != null)
                ? onLoading(context)
                : DefaultBuilderConfig.onLoading(context);
          }
          if (state is D) {
            return onData(context, state);
          }
          if (state is ErrorState<E>) {
            return (onError != null)
                ? onError(context, state)
                : DefaultBuilderConfig.onError(context, state);
          }
          return (otherwise != null) ? otherwise(context) : Container();
        };