Skip to content
pubscout

bloc_provider

1.1.0, released 9 days ago by mono0926.com

Provides BLoC to descendant widgets with O(1) access and automatic disposal.

WASM-ready
$ flutter pub add bloc_provider
Source repository

What it does

bloc_provider lets you create a BLoC instance and expose it to the widget subtree. The provided BLoC is retrieved in O(1) time and is disposed automatically when the provider's state is removed.

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

Use it when

  • You need a lightweight way to share a BLoC across widgets without adding a large dependency
  • You prefer O(1) lookup and automatic disposal of the BLoC
  • Your project already uses the classic BLoC pattern and wants a simple provider

Skip it when

  • You require a actively maintained package with richer features
  • You need code‑generation, scoped providers, or advanced state‑management capabilities
  • You are already using Riverpod, Provider, or flutter_bloc for state management

Strengths

  • O(1) access to the BLoC
  • Automatic disposal of the BLoC
  • Very small and simple API

Weaknesses

  • Minimally maintained and may lack future updates
  • Limited feature set compared to newer providers
  • No built‑in support for code‑gen or advanced scoping

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
0
void main()=>runApp(BlocProvider<CounterBloc>(creator:(_,__)=>CounterBloc(),child:MyApp()));
class MyApp extends StatelessWidget{ @override Widget build(BuildContext c){final bloc=BlocProvider.of<CounterBloc>(c);return MaterialApp(home:Scaffold(body:StreamBuilder<int>(stream:bloc.count,initialData:bloc.count.value,builder:(_,s)=>Text('count: ${s.data}'))),floatingActionButton:FloatingActionButton(onPressed:()=>bloc.increment.add(null),child:Icon(Icons.add)),);}}

Alternatives

Packages that do the same job and could replace bloc_provider.

  • provider

    Widely used, actively maintained, and supports simple dependency injection

  • bloc

    Full BLoC library with extensive tooling and community support

  • riverpod

    Modern, compile‑time safety and richer provider features