BLoC library
# BLoC library
- Stands for Business Logic Component.
# Resources
- The Best Flutter Bloc Complete Course - Visualise, Understand, Learn & Practice Bloc Concepts - YouTube
- Why We Use flutter_bloc for State Management (verygood.ventures)
# The benefits of Bloc
The Bloc library provides very good tooling and compared to other state management solutions that use Streams, it’s a pure gem.
- Reactive out of the box
Blocis a subclass ofStream, so you know it integrates nicely with just about anything you throw at it without any complications. Examples include:mapa Firestore real-timeStreamof data into aStreamof states.- Apply
RxDart operators on
Stream<State>andStream<Event>. For example,debounceTimeis useful for auto-search where you want to start searching for a query only after the user has stopped typing for a while.
Good tooling for VS Code and IntelliJ/Android Studio
Analytics without any additional work
- With the help of the
BlocDelegate, you can know about any action the user takes in any BLoC without cluttering up your codebase with analytics code.
- With the help of the
Testing
Streams is easy, testingBlocs is even easier- Dart is built with
Streams in mind and testing if a particular sequence of states has been emitted is simple with stream matchers. - Why would you leave it at just the matchers though when you can use the bloc_test package which, in my opinion, makes tests fun to write?
- Dart is built with
BIASED OPINION: The best documentation ever
So, if you want to have the benefits of immutable state, closely work with Streams whether for the purposes of testing or integration with other code, observe state changes happening across the app from a single place ( BlocDelegate ) easily to allow for pain-free analytics and at the same time keep your code as simple as possible, BLoC is truly the best available option out there.