Bloc Concurrency

Pub build codecov Star on Github Flutter Website Awesome Flutter Flutter Samples License: MIT Discord Bloc Library


A Dart package that exposes custom event transformers inspired by ember concurrency. Built to work with bloc.

Learn more at bloclibrary.dev!


Sponsors

Our top sponsors are shown below! [Become a Sponsor]


Event Transformers

Event Transformers

bloc_concurrency provides an opinionated set of event transformers:

  • concurrent - process events concurrently
  • sequential - process events sequentially
  • droppable - ignore any events added while an event is processing
  • restartable - process only the latest event and cancel previous event handlers

Usage

import 'package:bloc/bloc.dart';
import 'package:bloc_concurrency/bloc_concurrency.dart';

sealed class CounterEvent {}

final class CounterIncrementPressed extends CounterEvent {}

class CounterBloc extends Bloc<CounterEvent, int> {
  CounterBloc() : super(0) {
    on<CounterIncrementPressed>(
      (event, emit) async {
        await Future.delayed(Duration(seconds: 1));
        emit(state + 1);
      },
      /// Specify a custom event transformer from `package:bloc_concurrency`
      /// in this case events will be processed sequentially.
      transformer: sequential(),
    );
  }
}

Dart Versions

  • Dart 2: >= 2.12

Maintainers

Libraries

bloc_concurrency
Custom event transformers inspired by ember concurrency. Built to be used with the bloc state management package.