A State management library for Dart and Flutter using BLoCs (Business Logic Component)

Checkout the flutter version too: ezbloc_flutter


This library provides a simpler alternative for existing libraries which:

  • Require a lot of boilerplate code
  • Expose complexity of underlying reactive streams

Pros 👍

  • Easy to use and works out of the box
  • Complete abstraction over Streams and Subscriptions
  • No more states or events boilerplate bloat (just work with functions)


Easy Bloc hides all streams/yields, exposing only simple functions setState(), setBusy() and setError():

import 'package:ezbloc/ezbloc.dart';

class CounterBloc extends Bloc {
  void increment() => setState(value + 1);
  void decrement() => setState(value - 1);

void main() {
  final bloc = CounterBloc();

A bit more complex bloc:

AutoPersistedBloc can be used to save value on app exit, and recover again on app start. Keeps State in sync, shows error messages and loading indicator.

import 'package:ezbloc/ezbloc.dart';

class CounterBloc extends AutoPersistedBloc<CounterBloc, int> {
  void increment() async {
    if (value >= 10) {
      setError(StateError('Counter cannot go beyond 10'));
    await makeNetworkCall();
    setState(value + 1);

  void decrement() => setState(value - 1);

void main() async {
  final bloc = CounterBloc();
  await bloc.increment();

Bloc Monitor

You can monitor your blocs and create side effects simply by using a bloc monitor.

 class BroadcastPrinter extends BlocMonitor {
   void onBroadcast(String blocName, state, {String event}) {
     print('[$blocName] broadcast: $state ($event)');

For more details: bloc monitor


testBloc<CounterBloc, int>(
    'counter should work',
    bloc: () async => CounterBloc(0),
    expectBefore: (bloc) async => expect(bloc.isBusy, false),
    expectAfter: (bloc) async => expect(bloc.hasError, false),
    timeout: Duration(seconds: 1),
    expectedStates: emitsInOrder([0, 1, 2, 1]),
    job: (bloc) async {

Contribution ❤

Issues and pull requests are welcome

Please file feature requests and bugs at the issue tracker.