Guide · Open source
How to use bloc: install flutter_bloc and build your first Bloc
Updated · written with AI from the project's own documentation and checked against our catalogue data
Bloc is an open-source state management library for Dart and Flutter apps. It separates what the user sees from the business logic that decides what happens, which the project says makes code easier to test and reuse. This guide shows you how to add it to a project, what the package family contains, and where to find working examples.
Quick start
- 1Check your SDK. Confirm the Dart SDK or Flutter SDK is installed on your machine before you add any packages.
- 2Add flutter_bloc. Run flutter pub add flutter_bloc in your project folder to add the Flutter package.
- 3Read the core concepts. Review the official documentation at bloclibrary.dev to understand events, states and the Bloc pattern.
- 4Build a small Bloc. Follow the Flutter counter tutorial to create a CounterBloc and connect it to your widgets.
- 5Add tests. Use the bloc_test package to unit test your Bloc logic separately from the UI.
What do you need before you install bloc?
Bloc needs either the Dart SDK or the Flutter SDK installed on your machine. The library assumes you are comfortable with Dart and Flutter, and with streams and the BLoC design pattern. If those are new to you, work through a basic Flutter tutorial first.
- Dart SDK or Flutter SDK installed
- Working knowledge of Dart and Flutter
- Basic understanding of streams and the BLoC pattern
How do you install bloc in a Flutter project?
Bloc is installed through the Dart and Flutter package manager. For a Flutter app, the README gives this command to add the flutter_bloc package, which is the Flutter package in the family.
flutter pub add flutter_blocWhich bloc packages does the project include?
Bloc is a family of packages rather than a single library. The main ones are bloc, flutter_bloc, bloc_test and hydrated_bloc. Other packages in the repository include angular_bloc, bloc_concurrency, bloc_lint, bloc_tools and replay_bloc.
flutter_bloc is the Flutter package and is the one the README uses for installation. bloc_test is listed as the testing package, and hydrated_bloc is listed as a package in the family. Check each package's own README for its details.
- bloc: the core library
- flutter_bloc: the Flutter package
- bloc_test: testing support
- hydrated_bloc: a package in the family
- bloc_concurrency and bloc_lint: further packages in the repository
What does bloc help you separate?
The core goal is to separate presentation from business logic. The user interface shows state, while the Bloc decides how that state changes in response to events. The README says this separation facilitates testability and reusability.
The project's documentation at bloclibrary.dev has the full guides, and the repository includes a migration guide for upgrading.
- Presentation: the widgets the user sees
- Business logic: the code that decides what happens
- Testability and reusability: the stated benefits of the split
Where can you find examples to learn from?
The README links to several tutorials on bloclibrary.dev, including a Flutter counter, an infinite list, a login flow, a GitHub search, a weather app and a todos app. It also links a pure Dart CounterBloc example and a form validation example that uses bloc and flutter_bloc together.
Start with the counter example if you are new to the library, then move to form validation or asynchronous data loading.
- Flutter counter tutorial
- Flutter infinite list
- Flutter login with Firebase
- GitHub search
- Flutter weather
- Flutter todos
- Pure Dart CounterBloc example
- Form validation example
What people use it for
- Separating a Flutter screen's UI code from its business logic
- Managing asynchronous state such as data loading in a list or search screen
- Handling form validation with a Bloc that tracks input and errors
- Writing unit tests for business logic that does not depend on widgets
Frequently asked questions
Is bloc free to use?
Yes. The repository is licensed under the MIT license, which is an open-source licence. Check the LICENSE file in the repository for the full terms.
What do I need to install bloc?
You need the Dart SDK or the Flutter SDK. For a Flutter app, add the flutter_bloc package with flutter pub add flutter_bloc.
Is bloc good for beginners?
The README says the library assumes familiarity with streams and the BLoC pattern, so it is not aimed at people with no Dart or Flutter experience. Learn the basics of Flutter first.
Is bloc too much for a small app?
The README does not compare overhead for small projects. For very small apps, a simpler state approach may be enough, so weigh the trade-off for your own project.
How does bloc compare to Provider, Riverpod, GetX and MobX?
These are comparable state management projects. The README does not include a direct comparison, so read each project's documentation and try a small example before choosing.
Where is the official documentation?
The official documentation is at bloclibrary.dev, and each package has its own README in the repository on GitHub.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Bloc suits Flutter and Dart developers who want to separate UI code from business logic, especially for complex or asynchronous state and easier unit testing. Beginners without Dart or Flutter experience, or people building very small apps, may be better served by a simpler state approach.
Install options & downloads