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 Stream
s, it’s a pure gem.
- Reactive out of the box
Bloc
is a subclass ofStream
, so you know it integrates nicely with just about anything you throw at it without any complications. Examples include:map
a Firestore real-timeStream
of data into aStream
of states.- Apply
RxDart operators on
Stream<State>
andStream<Event>
. For example,debounceTime
is 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
Stream
s is easy, testingBloc
s is even easier- Dart is built with
Stream
s 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 Stream
s 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.