Skip to content
pubscout

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
$ flutter pub add bloc
Source repository

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.

  • riverpod

    Offers a different approach to state management with less boilerplate

Works with

Packages commonly used together with bloc: ones it builds on, ones built on it, and its own family.