ViewStateBuilder<T, B extends BlocBase<ViewState<T> > > constructor
ViewStateBuilder<T, B extends BlocBase<ViewState<T> > > ({
- Key? key,
- B? 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,
- BlocBuilderCondition<
ViewState< ? buildWhen,T> >
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,
};
},
);