blowe_bloc library
The blowe_bloc library provides a collection of
BLoC (Business Logic Component) classes, models, and widgets
to manage state and business logic in Flutter applications.
This library is built on top of the flutter_bloc package
and extends its functionality by providing additional BLoC
classes for loading, pagination, and watching data streams.
It also includes models for handling pagination and a variety
of widgets to easily integrate with the BLoC architecture.
Dependencies
The library depends on the flutter_bloc package for BLoC functionality.
Blowe Bloc
The core classes for managing state and business logic are located in the src/logic
directory. These include base classes for BLoC, events, and states,
as well as specialized BLoC classes for loading, pagination,
and watching data streams.
Models
The src/model directory contains models used by the BLoC classes, such as BloweNoParams
for representing no parameters and BlowePaginationModel for handling
paginated data.
Widgets
The src/widget directory includes various widgets that work with the BLoC classes to
provide UI components that react to state changes. These widgets include
buttons, listeners, dropdowns, list views, and text form fields.
Additionally, the selector subdirectory contains widgets for
selecting and managing multiple BLoC instances.
Classes
-
Bloc<
Event, State> -
Takes a
StreamofEventsas input and transforms them into aStreamofStatesas output. -
BlocBase<
State> - An interface for the core functionality implemented by both Bloc and Cubit.
-
BlocBuilder<
B extends StateStreamable< S> , S> -
BlocBuilder handles building a widget in response to new
states. BlocBuilder is analogous to StreamBuilder but has simplified API to reduce the amount of boilerplate code needed as well as bloc-specific performance improvements. Please refer to BlocListener if you want to "do" anything in response tostatechanges such as navigation, showing a dialog, etc... -
BlocBuilderBase<
B extends StateStreamable< S> , S> - Base class for widgets that build themselves based on interaction with a specified bloc.
-
BlocConsumer<
B extends StateStreamable< S> , S> -
BlocConsumer exposes a builder and listener in order react to new
states.
BlocConsumer is analogous to a nested
BlocListenerandBlocBuilderbut reduces the amount of boilerplate needed. BlocConsumer should only be used when it is necessary to both rebuild UI and execute other reactions to state changes in the bloc. -
BlocEventSink<
Event extends Object?> - An ErrorSink that supports adding events.
-
BlocListener<
B extends StateStreamable< S> , S> -
Takes a BlocWidgetListener and an optional bloc and invokes
the listener in response to
statechanges in the bloc. It should be used for functionality that needs to occur only in response to astatechange such as navigation, showing aSnackBar, showing aDialog, etc... The listener is guaranteed to only be called once for eachstatechange unlike thebuilderinBlocBuilder. -
BlocListenerBase<
B extends StateStreamable< S> , S> - Base class for widgets that listen to state changes in a specified bloc.
- BlocObserver
- An interface for observing the behavior of Bloc instances.
-
BlocProvider<
T extends StateStreamableSource< Object?> > -
Takes a
createfunction that is responsible for creating the Bloc or Cubit and a child which will have access to the instance viaBlocProvider.of(context). It is used as a dependency injection (DI) widget so that a single instance of a Bloc or Cubit can be provided to multiple widgets within a subtree. -
BlocSelector<
B extends StateStreamable< S> , S, T> - BlocSelector is analogous to BlocBuilder but allows developers to filter updates by selecting a new value based on the bloc state. Unnecessary builds are prevented if the selected value does not change.
-
BloweAddSearchHistory<
T> - Event used to add an item to the search history.
-
BloweBloc<
T, P> - BloweBloc is an abstract class that extends Bloc and serves as the base for managing specific events and states in the blowe_bloc package. It provides a structure for handling data fetching, updating, resetting, and pagination.
-
BloweBlocButton<
B extends BloweBloc< T, dynamic> , N extends ButtonStyleButton, T> - A button widget that uses a BloweBloc to determine if the button should be enabled. It rebuilds based on the state of the specified BloweBloc.
-
BloweBlocListener<
B extends BloweBloc< T, dynamic> , T> - A widget that listens to the state changes of a BloweBloc and triggers the corresponding callback functions for each state type.
-
BloweBlocSelector<
B extends BloweBloc< T, dynamic> , T> - A widget that uses a BlocSelector to determine if the widget should be enabled. It rebuilds based on the state of the specified BloweBloc.
- BloweBoolFormController
- A controller for a form field that uses a boolean value.
- BloweBoolFormListTile
- A form field widget that wraps a SwitchListTile or CheckboxListTile.
- BloweClearSearchHistory
- Event used to clear the search history.
-
BloweCompleted<
T> - State indicating that an operation has completed successfully.
-
BloweDropdownButtonFormField<
T> - A dropdown button form field widget that allows customization of the dropdown items, icon, suffix icon, label text, and validator.
-
BloweError<
T> - State indicating that an error has occurred.
- BloweEvent
- Base event class for BloweBloc.
-
BloweFetch<
P> - Event used to initiate data fetching. Contains a parameter of type P.
-
BloweFetchMore<
P> - Event used to fetch more data, typically used in pagination. Contains a parameter of type P.
- BloweForceError
- Event used to force an error state directly.
- BloweFormErrorText
- A widget that displays an error message for a form field.
-
BloweInitial<
T> - Initial state of the Bloc.
-
BloweInProgress<
T> - State indicating that an operation is in progress.
-
BloweLoadBloc<
T, P> - BloweLoadBloc extends BloweBloc and provides a structure for loading data using a provided load method.
- BloweLoadSearchHistory
- Event used to load the search history.
- BloweMultiBlocSelector
- A widget that monitors multiple BloweBlocs and determines if the widget should be enabled based on the state of all provided BloweBlocs.
- BloweMultiBlocSelectorState
- State class for BloweMultiBlocSelector.
- BloweNoParams
- A class representing no parameters. This can be used when an operation does not require any parameters.
- BloweNumberFormController
- A controller for the number input field.
- BloweNumberFormListTile
- A form field widget that provides a number selector with increment and decrement buttons.
-
BlowePaginationBloc<
T extends BlowePaginationModel, P> - BlowePaginationBloc extends BloweBloc and provides a structure for handling paginated data using a provided load method.
-
BlowePaginationListView<
B extends BlowePaginationBloc< BlowePaginationModel< , T, P, G>T> , P> - A widget that displays a paginated list of items using a BlowePaginationBloc. It handles loading, error, and completed states of the BlowePaginationBloc.
-
BlowePaginationModel<
T> - Class representing a pagination model. This class is used to handle paginated data.
-
BloweRadiusForm<
T> - A form field widget that manages a list of radius list tiles.
-
BloweRadiusFormController<
T> - A controller for a form field that manages a single selected item.
-
BloweRemoveSearchHistory<
T> - Event used to remove an item from the search history.
- BloweReset
- Event used to reset the Bloc to its initial state.
-
BloweSearchBloc<
T extends BloweSerializableItem, P extends BloweSearchParams> - BloweSearchBloc extends BlowePaginationBloc and provides a structure for handling paginated data along with managing a search history.
-
BloweSearchDelegate<
B extends BloweSearchBloc< T, P> , T extends BloweSerializableItem, P extends BloweSearchParams> - A delegate for searching with automatic history management and debounce support.
- BloweSearchParams
-
Base class for search parameters that includes a
queryfield. - BloweSerializableItem
-
A base class that requires implementing classes to have
a
toJsonmethod for serialization. -
BloweState<
T> - Base state class for BloweBloc.
- BloweTextFormField
- A text form field widget that supports optional obscuring of text, custom validation, custom icons, and multiline input.
-
BloweUpdateData<
T> - Event used to update the current data. Contains data of type T.
-
BloweWatchBloc<
T, P> - BloweWatchBloc extends BloweBloc and provides a structure for watching data changes using a provided watch method.
-
Change<
State> -
A Change represents the change from one
Stateto another. A Change consists of the currentState and nextState. - Closable
- An object that must be closed when no longer in use.
-
Cubit<
State> - A Cubit is similar to Bloc but has no notion of events and relies on methods to emit new states.
-
Emittable<
State extends Object?> - An object that can emit new states.
-
EmittableStateStreamableSource<
State> - A StateStreamableSource that can emit new states.
-
Emitter<
State> - An Emitter is a class which is capable of emitting new states.
- ErrorSink
- A generic destination for errors.
- MultiBlocListener
- Merges multiple BlocListener widgets into one widget tree.
- MultiBlocObserver
-
A BlocObserver which supports registering multiple BlocObserver
instances. This is useful when maintaining multiple BlocObserver instances
for different functions e.g.
LoggingBlocObserver,ErrorReportingBlocObserver. - MultiBlocProvider
- Merges multiple BlocProvider widgets into one widget tree.
- MultiRepositoryProvider
- Merges multiple RepositoryProvider widgets into one widget tree.
-
RepositoryProvider<
T> -
Takes a
createfunction that is responsible for creating the repository and achildwhich will have access to the repository viaRepositoryProvider.of(context). It is used as a dependency injection (DI) widget so that a single instance of a repository can be provided to multiple widgets within a subtree. -
StateStreamable<
State> - A Streamable that provides synchronous access to the current state.
-
StateStreamableSource<
State> - A StateStreamable that must be closed when no longer in use.
-
Streamable<
State extends Object?> - An object that provides access to a stream of states over time.
-
Transition<
Event, State> - A Transition is the change from one state to another. Consists of the currentState, an event, and the nextState.
Enums
- BloweBoolListTileType
- Enum for specifying the type of ListTile to be used.
Extensions
- ReadContext on BuildContext
- Exposes the read method.
- SelectContext on BuildContext
-
Adds a
selectmethod on BuildContext. - WatchContext on BuildContext
- Exposes the watch method.
Typedefs
-
BlocBuilderCondition<
S> = bool Function(S previous, S current) -
Signature for the
buildWhenfunction which takes the previousstateand the currentstateand is responsible for returning a bool which determines whether to rebuild BlocBuilder with the currentstate. -
BlocListenerCondition<
S> = bool Function(S previous, S current) -
Signature for the
listenWhenfunction which takes the previousstateand the currentstateand is responsible for returning a bool which determines whether or not to call BlocWidgetListener of BlocListener with the currentstate. -
BlocWidgetBuilder<
S> = Widget Function(BuildContext context, S state) -
Signature for the
builderfunction which takes theBuildContextandstateand is responsible for returning a widget which is to be rendered. This is analogous to thebuilderfunction in StreamBuilder. -
BlocWidgetListener<
S> = void Function(BuildContext context, S state) -
Signature for the
listenerfunction which takes theBuildContextalong with thestateand is responsible for executing in response tostatechanges. -
BlocWidgetSelector<
S, T> = T Function(S state) -
Signature for the
selectorfunction which is responsible for returning a selected value,T, based onstate. -
BloweBlocWidgetListener<
T, S extends BloweState< T> > = void Function(BuildContext context, S state) - Typedef for a widget listener function used by BloweBlocListener.
- BloweBlocWidgetSelectorBuilder = Widget Function(BuildContext context, bool enabled)
- Typedef for a widget builder function used by BloweBlocSelector.
- BloweBoolFormListTileTitleBuilder = String Function(BuildContext context)
- Typedef for a title builder function used by BloweBoolFormListTile.
- BloweBoolFormListTileValidator = String? Function(BuildContext context, bool value)
- Typedef for a validator function used by BloweBoolFormListTile.
- BloweDropdownButtonFormFieldIconBuilder = Widget? Function(BuildContext context)
- Typedef for an icon builder function used by BloweDropdownButtonFormField.
- BloweDropdownButtonFormFieldLabelTextBuilder = String Function(BuildContext context)
- Typedef for a label text builder function used by BloweDropdownButtonFormField.
- BloweDropdownButtonFormFieldSuffixIconBuilder = Widget? Function(BuildContext context)
- Typedef for a suffix icon builder function used by BloweDropdownButtonFormField.
-
BloweDropdownButtonFormFieldValidator<
T> = String? Function(BuildContext context, T? value) - Typedef for a validator function used by BloweDropdownButtonFormField.
-
BloweDropdownMenuItemBuilder<
T> = DropdownMenuItem< T> Function(BuildContext context, T item) - Typedef for a dropdown menu item builder function used by BloweDropdownButtonFormField.
-
BloweDropdownSelectedItemBuilder<
T> = Widget Function(BuildContext context, T item) - Typedef for a custom widget builder for the selected item in the dropdown.
-
BloweFetchParamsProvider<
P> = P Function() - Typedef for a function that provides parameters for the BloweFetch event.
-
BloweGroupHeaderBuilder<
T, G> = Widget Function(BuildContext context, G group, List< T> items) - Typedef for a widget builder function used to build the group header.
-
BloweItemFilter<
T> = bool Function(T item) - Typedef for a function that filters items in the list.
-
BloweItemGrouper<
T, G> = G Function(T item) - Typedef for a function that groups items in the list.
- BloweMultiBlocWidgetSelectorBuilder = Widget Function(BuildContext context, bool enabled)
- Typedef for a widget builder function used by BloweMultiBlocSelector.
- BloweNumberFormListTileTitleBuilder = String Function(BuildContext context)
- A typedef for the title builder function used by BloweNumberFormListTile.
- BloweNumberFormListTileValidator = String? Function(BuildContext context, int value)
- A typedef for the validator function used by BloweNumberFormListTile.
- BlowePaginationErrorBuilder = Widget Function(BuildContext context, Exception error)
- Typedef for a widget builder function used to build the error widget.
-
BlowePaginationListViewItemBuilder<
T> = Widget Function(BuildContext context, T item) - Typedef for a widget builder function used by BlowePaginationListView.
-
BloweRadiusFormListTileTitleBuilder<
T> = String Function(BuildContext context, T item) - Typedef for a title builder function used by BloweRadiusFormListTile.
-
BloweRadiusFormValidator<
T> = String? Function(BuildContext context, T? value) - Typedef for a validator function used by BloweRadiusForm.
- BloweSearchEmptyWidgetBuilder = Widget Function(BuildContext context, String query)
- A typedef for the empty widget builder function used in BloweSearchDelegate.
-
BloweSearchInitialBuilder<
T> = Widget Function(BuildContext context, void close(BuildContext context, T? result)) - A typedef for the initial builder function used in BloweSearchDelegate.
-
BloweSearchItemBuilder<
T> = Widget Function(BuildContext context, T item, void close(BuildContext context, T? result), void save(T item)) - A typedef for the item builder function used in BloweSearchDelegate.
-
BloweSearchParamsProvider<
P> = P Function(String query) - A typedef for the params provider function used in BloweSearchDelegate.
- BloweTextFormFieldHintTextBuilder = String Function(BuildContext context)
- Typedef for a hint text builder function used by BloweTextFormField.
- BloweTextFormFieldLabelTextBuilder = String Function(BuildContext context)
- Typedef for a label text builder function used by BloweTextFormField.
- BloweTextFormFieldOnTap = void Function(BuildContext context)
- Typedef for an onTap callback used by BloweTextFormField.
- BloweTextFormFieldPrefixIconBuilder = Widget Function(BuildContext context)
- Typedef for a prefix icon builder function used by BloweTextFormField.
- BloweTextFormFieldSuffixIconBuilder = Widget Function(BuildContext context, bool obscureText, VoidCallback toggleObscureText)
- Typedef for a suffix icon builder function used by BloweTextFormField.
-
BloweTextFormFieldValidator<
T> = String? Function(BuildContext context, T? value) - Typedef for a validator function used by BloweTextFormField.
-
EventHandler<
Event, State> = FutureOr< void> Function(Event event, Emitter<State> emit) -
An event handler is responsible for reacting to an incoming
Eventand can emit zero or more states via the Emitter. -
EventMapper<
Event> = Stream< Event> Function(Event event) - Signature for a function which converts an incoming event into an outbound stream of events. Used when defining custom EventTransformers.
-
EventTransformer<
Event> = Stream< Event> Function(Stream<Event> events, EventMapper<Event> mapper) - Used to change how events are processed. By default events are processed concurrently.
Exceptions / Errors
- ProviderNotFoundException
-
The error that will be thrown if
Provider.offails to find aProvideras an ancestor of the BuildContext used.