ViewStateListener<T, B extends BlocBase<ViewState> > constructor
ViewStateListener<T, B extends BlocBase<ViewState> > ({
- Key? key,
- B? bloc,
- BlocListenerCondition<
ViewState> ? listenWhen, - LoadingCallback? onLoading,
- RefreshingCallback<
T> ? onRefreshing, - SuccessCallback<
T> ? onSuccess, - EmptyCallback? onEmpty,
- ErrorCallback? onError,
- Widget? child,
Implementation
ViewStateListener({
super.key,
super.bloc,
super.listenWhen,
LoadingCallback? onLoading,
RefreshingCallback<T>? onRefreshing,
SuccessCallback<T>? onSuccess,
EmptyCallback? onEmpty,
ErrorCallback? onError,
super.child,
}) : super(
listener: (BuildContext context, ViewState state) {
if (state is Loading) {
onLoading?.call(context);
} else if (state is Refreshing<T>) {
onRefreshing?.call(context, state.data);
} else if (state is Success<T>) {
onSuccess?.call(context, state.data);
} else if (state is Empty) {
onEmpty?.call(context);
} else if (state is Failure) {
onError?.call(context, state.error);
}
},
);