bloc
A predictable state management library that helps implement the BLoC design pattern
Bloc is a state management library for Flutter and AngularDart apps that separates business logic from the UI using a predictable event-in, state-out pattern, making apps easier to test and debug.
This repository is a state management library for apps built with Flutter (Google's mobile and web toolkit) or AngularDart. State management is the problem of tracking what an app is doing at any given moment: whether a user is logged in, what items are in a cart, what data has loaded from a server. Without a clear structure for this, the logic can become tangled and difficult to test.
The library is built around the BLoC pattern, which stands for Business Logic Component. The core idea is to draw a clean line between what the user sees and the rules that govern how the app behaves. Events come in from the UI, a bloc processes them according to defined rules, and emits new states that the UI then reflects. This predictable one-way flow makes it easier to trace bugs, write automated tests, and reuse logic across different parts of an app.
The repository ships as a family of separate packages rather than one large bundle. The core bloc package contains the fundamental logic. flutter_bloc provides widgets that connect a Flutter UI to a bloc. hydrated_bloc adds persistence so that state survives an app restart. replay_bloc adds undo and redo support. bloc_test provides utilities for writing automated tests against blocs. bloc_concurrency handles situations where multiple events arrive at once and you need to decide whether to queue them, run them in parallel, or drop duplicates. bloc_lint adds linting rules to catch common mistakes before code ships.
Official documentation, tutorials, and migration guides live at bloclibrary.dev. The README links to worked examples covering a counter, an infinite scrolling list, a login screen, a GitHub search feature, and a weather app. These serve as starting points for new projects or as references for common patterns.
The library is MIT-licensed and free to use in personal and commercial projects. It is listed as a recommended option in the official Flutter documentation and has an active Discord community.
Where it fits
- Manage login state in a Flutter app so the UI automatically updates when a user logs in or out.
- Build an infinite-scrolling list in Flutter where more items load automatically as the user scrolls.
- Add undo and redo support to any part of a Flutter app using the replay_bloc package.
- Write automated tests for app business logic without needing a running UI or device.