Skip to content
pubscout

hooked_bloc

1.7.0, released a year ago by iteo.com

Simplifies Bloc and Cubit usage in Flutter using hooks.

WASM-ready
$ flutter pub add hooked_bloc
Source repository

What it does

It provides a set of hooks like useBloc, useBlocBuilder, and useBlocListener that abstract away boilerplate around BlocProvider, BlocBuilder, and BlocListener. Developers can access blocs and consume states or actions inside HookWidget classes with less code.

AI-written summary of version 1.7.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You are already using flutter_hooks in your application.
  • You want to reduce the boilerplate of BlocBuilder and BlocListener in your widget trees.

Skip it when

  • You do not use flutter_hooks or prefer traditional StatefulWidget and StatelessWidget implementations.
  • You are using a different state management library like Riverpod or Provider.

Strengths

  • Significantly reduces widget tree boilerplate for Bloc and Cubit.
  • Provides convenient hooks for builders, comparative builders, listeners, and action streams.
  • Integrates well with dependency injection tools like GetIt.

Weaknesses

  • Requires the use of flutter_hooks and HookWidget across your widgets.
  • Tight coupling between view logic and Flutter hooks.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
5

Add the dependency to pubspec.yaml and optionally wrap your app in HookedBlocConfigProvider for global injection and conditions.

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

  @override
  Widget build(BuildContext context) {
    final cubit = useBloc<CounterCubit>();
    final state = useBlocBuilder(cubit);

    return MaterialApp(
      home: Scaffold(
        floatingActionButton: FloatingActionButton(
          onPressed: () => cubit.increment(),
          child: const Icon(Icons.add),
        ),
        body: Center(child: Text("The button has been pressed $state times")),
      ),
    );
  }
}

Alternatives

Packages that do the same job and could replace hooked_bloc.

  • riverpod

    If you want a complete alternative state management and dependency injection solution without using BLoC.

Works with

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