ViewStateBuilder<T, B extends BlocBase<ViewState<T> > > constructor
ViewStateBuilder<T, B extends BlocBase<ViewState<T> > > ({
- Key? key,
- B? bloc,
- InitialBuilder? onReady,
- LoadingBuilder? onLoading,
- RefreshingBuilder<
T> ? onRefreshing, - SuccessBuilder<
T> ? onSuccess, - EmptyBuilder? onEmpty,
- ErrorBuilder? onError,
- BlocBuilderCondition<
ViewState< ? buildWhen,T> >
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,
};
},
);