A reactive flux-like state management library using the BLoC pattern.
The goal of the bloc_flux package is to take the best parts of the Flux and BLoC state management patterns.
The general architecture of a bloc_flux application is similar to that of a Flux application. A bloc_flux application consists of a single Dispatcher that dispatches Actions to all registered Blocs. All data flows from component to component in Observables. Observables (from RxDart) are like streams with more built in features for stream transformations and are by default synchronous whereas most stream implementations are asynchronous. The only input and output to the Dispatcher occur in the form of Actions. The Blocs then receive any dispatched Actions from the Dispatchers actionObservable. The Blocs do not receive input from anywhere else. Blocs then update their state in response to the Action. Any changed values will be added to an output Observable. Views listen to the output observables on the Blocs and rebuild whenever a new value is available. The output observable also emits the last emitted value to every new listener so default init values do not have to be specified.
Actions are the only form of input to the Blocs (via the Dispatcher). Actions represent a single event happening in the application. These can be anything from a UI event like a button click to asynchronous network responses.
Blocs manage the state of a domain of the application. The domain can be anything from a single widget/component to entire app/web pages. Blocs can also be used to perform IO operations like networks calls and state persistence. This is the equivalent to a flux or redux store.
Dispatchers are the central hub that all data flows through. Data can be dispatched to a Dispatcher by calling the dispatch(Action action) method. All data is wrapped in an Action. The dispatcher will then dispatch the Action to all registered Blocs. The dispatcher allows for easy logging and debugging as any events affecting the state of the application will flow through the Dispatcher and can be logged.
Fields represent a single output from a Bloc. They allow access to an observable (stream) and the last value that was emitted from the observable. Most Blocs will contain multiple fields.
The main goal of bloc_flux is to combine the reusability and compartmentalization of the BLoC pattern and the centralization of the Flux pattern.
This diagram represents that state management architecture of a simple counting app that has 3 main functions:
In bloc_flux all data flow is through Observables (streams). In the above diagram every arrow represents a stream. An action stream is a stream which only ever emits Actions. A data stream stream refers to any stream not containing exclusively Actions. This can be any data from primitives to complex objects.
Please file feature requests and bugs at the issue tracker.
Add this to your package's pubspec.yaml file:
dependencies: bloc_flux: ^0.1.0
You can install packages from the command line:
$ pub get
$ flutter pub get
Alternatively, your editor might support
pub get or
flutter pub get.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
|0.1.0||Feb 27, 2019|
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
We analyzed this package on Jun 25, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, web, other
No platform restriction found in primary library
lib/src/serializers/composite_serializers.dart. (-26.12 points)
lib/src/serializers/composite_serializers.dart failed with 1 error, 3 hints:
line 20 col 7: Missing concrete implementation of getter Serializers.builderFactories.
line 168 col 11: Use rethrow to rethrow a caught exception.
line 301 col 16: Don't explicitly initialize variables to null.
line 320 col 16: Don't explicitly initialize variables to null.
lib/src/field/field_id.dart. (-0.50 points)
lib/src/field/field_id.dart reported 1 hint:
line 35 col 40: Avoid types as parameter names.
lib/src/query/state_query.dart. (-0.50 points)
lib/src/query/state_query.dart reported 1 hint:
line 59 col 43: Avoid types as parameter names.
Support latest dependencies. (-10 points)
The version constraint in
pubspec.yaml does not support the latest published versions for 1 dependency (1 direct:
Maintain an example. (-10 points)
Create a short demo in the
example/ directory to show how to use this package.
Common filename patterns include
bloc_flux.dart. Packages with multiple examples should provide
For more information see the pub package layout conventions.
|Dart SDK||>=2.0.0 <3.0.0|