bloc
9.2.1, released 6 months ago by bloclibrary.dev
A Dart library for implementing the BLoC pattern with Cubits and Blocs.
Flutter FavoriteWASM-readyRock solid
What it does
It provides a lightweight, reactive state management solution that separates business logic from UI. The library defines Bloc and Cubit classes that emit state changes through streams, enabling easy testing and composability.
AI-written summary of version 9.2.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- Implementing the BLoC pattern in Flutter or Dart apps
- Need testable, reusable business logic
- Managing complex state with clear separation from UI
Skip it when
- Very small or simple apps where a simpler state solution suffices
- Projects that require heavy UI logic inside widgets
Strengths
- High testability and clear separation of concerns
- Large community and extensive documentation
- Supports both Bloc and Cubit for flexibility
Weaknesses
- Requires understanding of streams and reactive patterns
- Some boilerplate for setting up Blocs/Cubits
- Learning curve for new developers
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
```dart
class CounterCubit extends Cubit<int> {
CounterCubit() : super(0);
void increment() => emit(state + 1);
}
```Alternatives
Packages that do the same job and could replace bloc.
Works with
Packages commonly used together with bloc: ones it builds on, ones built on it, and its own family.
- bloc_lintSame familyOfficial lint rules for development when using the bloc state management library.
- bloc_toolsSame familyCommand-line tools for generating and linting bloc and cubit components.
- flutter_blocBuilt on blocFlutter widgets to easily integrate blocs and cubits for state management.
- bloc_testBuilt on blocA testing library that makes it easy to test blocs and cubits.
- bloc_concurrencyBuilt on blocCustom event transformers for the bloc state management package.
- hydrated_blocBuilt on blocAutomatically persists and restores bloc and cubit states.
- talker_bloc_loggerBuilt on blocLightweight and customizable logger for BLoC and Cubit built on Talker.
- bloc_presentation_testBuilt on blocA testing library for Blocs and Cubits utilizing BlocPresentationMixin.