flutter_bloc
9.1.1, released 2 years ago by bloclibrary.dev
Flutter widgets to easily integrate blocs and cubits for state management.
Flutter FavoriteWASM-readyRock solidQuiet but busy
What it does
Provides widgets like BlocBuilder, BlocListener, and BlocProvider to help integrate BLoC and Cubit state management instances into the Flutter widget tree. It manages lifecycle, dependency injection, and state reactions without requiring code generation.
AI-written summary of version 9.1.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are using the bloc package for state management in Flutter
- You need a structured way to separate business logic from UI
- You want to inject blocs into the widget tree and rebuild on state changes
Skip it when
- You prefer a simpler or less boilerplate-heavy state management solution like riverpod
- You are not using the bloc package
Strengths
- Tight integration with the bloc state management library
- Built-in dependency injection via BlocProvider
- Reduces boilerplate compared to using raw StreamBuilders
Weaknesses
- Can introduce significant boilerplate for simple states
- Steeper learning curve for developers new to the BLoC pattern
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
BlocProvider(
create: (_) => CounterCubit(),
child: CounterPage(),
);Alternatives
Packages that do the same job and could replace flutter_bloc.
Works with
Packages commonly used together with flutter_bloc: ones it builds on, ones built on it, and its own family.
- blocflutter_bloc depends on itA Dart library for implementing the BLoC pattern with Cubits and Blocs.
- providerflutter_bloc depends on itA lightweight wrapper around InheritedWidget for state management
- bloc_testSame familyA testing library that makes it easy to test blocs and cubits.
- bloc_concurrencySame familyCustom event transformers for the bloc state management package.
- hydrated_blocSame familyAutomatically persists and restores bloc and cubit states.
- 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.
- replay_blocSame familyAdds automatic undo and redo support to bloc and cubit states.