defaultBuilder<D extends DataState, E> function

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

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()? onLoading,
  required Widget Function(D) onData,
  Widget Function(ErrorState<E> state)? onError,
  Widget Function()? otherwise,
}) =>
        (context, state) {
          if (state is LoadingState) {
            return (onLoading != null)
                ? onLoading()
                : DefaultBuilderConfig.onLoading();
          }
          if (state is D) {
            return onData(state);
          }
          if (state is ErrorState<E>) {
            return (onError != null)
                ? onError(state)
                : DefaultBuilderConfig.onError<E>(state);
          }
          return (otherwise != null) ? otherwise() : Container();
        };