defaultBuilder<D extends DataState, E> function
Widget Function(BuildContext, BlocState)
defaultBuilder<D extends DataState, E>({
- Widget onLoading()?,
- required Widget onData(
- D
- Widget onError(
- ErrorState<
E> state
- ErrorState<
- 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();
};