generic_bloc

Last updated:

0 purchases

generic_bloc Image
generic_bloc Images
Add to Cart

Description:

generic bloc

Example usage GenericOneBLoc #
The generic bloc provides basic functions to your data such as loaded
state, loaded (but not fully loaded) state, and fully loaded. You can use it
to add such states for any type of data. The package includes GenericBloc
for lists and GenericOneBloc for single values.
In Bloc #
final GenericOneBloc<bool> activeBanner = GenericOneBloc<bool>();
copied to clipboard
In UI #
return BlocBuilder<GenericOneBloc<bool>, GenericOneState<bool>>(
bloc: context.read<SomeBloc>().dayDelivery,
builder: (context, state) => state.map(
loadingState: (state) => const Skeleton(),
loadedState: (state) => SomeWidget(
isActive: state.data,
),
errorState: (state) => const Text(state.exception),
),
);
copied to clipboard

Example usage GenericBLoc #
In Bloc #
final GenericBloc<Product> products = GenericBloc<Product>();
copied to clipboard
In UI #
BlocBuilder<GenericBloc<Product>, GenericState<Product>>(
bloc: context.read<SomeBloc>().products,
builder: (context, state) => state.map(
loadingState: (loadingState) => Skeleton(),
loadedState: (loadedState) => Column(
children: [
...loadedState.data.map((e) => Widget(e)),
Skeleton(),
],
),
fullLoadedState: (fullLoadedState) => Column(
children: fullLoadedState.data.map(
(e) => Widget(e),
),
),
errorState: (errorState) => Text(errorState.exception),
),
)
copied to clipboard
How to send events ? (generic/genericOne) #
genericBloc #
someGenericBloc.add(GenericEvent.showLoading());
someGenericBloc.add(GenericEvent.showLoaded(data: someData));
someGenericBloc.add(GenericEvent.showFullLoaded(data: someData));
someGenericBloc.add(GenericEvent.showError(exception: 'error'));
copied to clipboard
genericOneBloc #
someGenericBloc.add(GenericOneEvent.showLoading());
someGenericBloc.add(GenericOneEvent.showLoaded(data: someData));
someGenericBloc.add(GenericOneEvent.showError(exception: 'error'));
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.