talira

Predictable state management for Dart and Flutter with the BLoC pattern

open sourceMITfree

Bloc is a state management library for Dart and Flutter that implements the BLoC (Business Logic Component) pattern, keeping business logic apart from presentation so it can be tested and reused. A Cubit exposes functions that emit new states; a Bloc takes events and maps them to states; both can be observed for every change and transition. The flutter_bloc package adds widgets such as BlocBuilder, BlocSelector, BlocListener, BlocConsumer and BlocProvider that rebuild or react when state changes, and companion packages add testing (bloc_test), persisted state (hydrated_bloc), undo and redo (replay_bloc) and event concurrency controls. It is made by Felix Angelov.

Problems it solves

  • separate business logic from UI in my Flutter app
  • manage app state in Flutter in a way I can unit test
  • rebuild only the Flutter widgets that depend on a piece of state

Features

  • Cubit: functions that emit new states
  • Bloc: events mapped to states, with observable transitions
  • flutter_bloc widgets: BlocBuilder, BlocSelector, BlocListener, BlocConsumer, BlocProvider
  • RepositoryProvider for dependency injection
  • Companion packages for testing, persisted state, undo/redo and event concurrency

Alternatives

The same job

These do what Bloc does.

  1. provider InheritedWidgets, but simple
  2. GetX State management, dependency injection and routing for Flutter in one package
  3. MobX.dart Reactive state management for Dart and Flutter, a port of MobX
  4. June Flutter state management that feels like Flutter
  5. Riverpod Reactive caching and data-binding framework for Dart and Flutter

Compare Bloc with the top 3