ViewStateListener<T, B extends BlocBase<ViewState<T> > > constructor
ViewStateListener<T, B extends BlocBase<ViewState<T> > > ({
- Key? key,
- B? bloc,
- BlocListenerCondition<
ViewState< ? listenWhen,T> > - LoadingCallback? onLoading,
- RefreshingCallback<
T> ? onRefreshing, - @Deprecated('This callback will removed. Use "onData" instead.') SuccessCallback<
T> ? onSuccess, - DataCallback<
T> ? onData, - EmptyCallback? onEmpty,
- ErrorCallback? onError,
- Widget? child,
Implementation
ViewStateListener({
super.key,
super.bloc,
super.listenWhen,
LoadingCallback? onLoading,
RefreshingCallback<T>? onRefreshing,
@Deprecated('This callback will removed. Use "onData" instead.')
SuccessCallback<T>? onSuccess,
DataCallback<T>? onData,
EmptyCallback? onEmpty,
ErrorCallback? onError,
super.child,
}) : assert(
!(onSuccess != null && onData != null),
'The onSuccess and onData callbacks should NOT be used together. The onSuccess callback is deprecated and can be safely removed.',
),
super(
listener: (BuildContext context, ViewState<T> state) {
return switch (state) {
Initial<T>() => () {},
Loading<T>() => onLoading?.call(context),
Refreshing<T>(value: final value) =>
onRefreshing?.call(context, value),
Data<T>(value: final value) =>
(onData ?? onSuccess)?.call(context, value),
Empty<T>() => onEmpty?.call(context),
Failure<T>(error: final value) => onError?.call(context, value)
};
},
);