A flutter_bloc reimplementation based on flutter_hooks for BlocBuilder, BlocListener, BlocConsumer and MultiBlocListener.

Usage as flutter_bloc

MultiBlocListener, BlocBuilder, BlocListener and BlocConsumer

They work exactly the same as the original. See the flutter_bloc documentation.


The useBloc hook function allows to listen state changes and rebuild the widget if necessary.

C useBloc<C extends Cubit<S>, S>({
  /// cubit to subscribe. if it is null, it will be infered
  C cubit,

  /// If `onEmitted` is not provided or its invocation returns `true`,
  /// the widget will rebuild.
  BlocHookListener<S> onEmitted,

It can be used into a HookBuilder:

HookBuilder(builder: (ctx) {
  final counter = useBloc<CounterCubit, int>(
    onEmitted: (_, prev, curr) {
      print('listener: $prev $curr');
      return true;
  return Text(
    style: Theme.of(context).textTheme.headline4,

And also into a widget that extends a HookWidget:

class BlocBuilder<C extends Cubit<S>, S> extends HookWidget
    with CubitComposer<C>, BlocBuilderInterface<C, S> {
  const BlocBuilder({
    Key? key,
    @required this.builder,
  })  : assert(builder != null),
        super(key: key);

  final C cubit;

  final BlocWidgetBuilder<S> builder;

  final BlocBuilderCondition<S> buildWhen;

  Widget build(BuildContext context) {
    final _cubit = useBloc<C, S>(
      cubit: cubit,
      onEmitted: (context, previous, state) {
        return buildWhen?.call(previous, state) ?? true;
    return builder(context, _cubit.state);

Alternative to MultiBlocBuilder

The issue with MultiBlocBuilder is that it could be either type safety or have an unliminit number of inputs (expending to much code). But with useBloc comes to the rescue.

class MyMultiBlocBuilder extends HookWidget {
  const MyMultiBlocBuilder({Key? key}) : super(key: key);

  Widget build(BuildContext context){
    // onEmitted is called every time that the state is emitter in a cubit/bloc
    final cubitA = useBloc<CubitA, int>(onEmitted: (context, previousState, state){
      // with true, the widget rebuild, otherwise, it behave like a BlocListener
      return buildWhenA?.call(previousState, state) ?? true;

    final blocB = useBloc<BlocB, String>(onEmitted: (context, previousState, state){
      // If you also want to have a BlocListener behavior, you can add some code here
      if(listenWhen?.call(previousState, state) ?? true){
        listener(context, state);
      return buildWhenB?.call(previousState, state) ?? true;

    // always rebuild when cubit emits a new state
    final cubitC = useBloc<CubitC, double>();

    return Column(
      children: [