{"id":22726436,"url":"https://github.com/mono0926/bloc_provider","last_synced_at":"2026-03-15T12:43:22.092Z","repository":{"id":56783093,"uuid":"159621211","full_name":"mono0926/bloc_provider","owner":"mono0926","description":"Provides bloc to descendant widget (O(1)), and the bloc is disposed appropriately by state that the bloc_provider holds internally.","archived":false,"fork":false,"pushed_at":"2022-08-16T00:54:48.000Z","size":285,"stargazers_count":115,"open_issues_count":4,"forks_count":17,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-04-07T19:21:17.113Z","etag":null,"topics":["bloc","business-logic-component","dart","flutter","inherited-widget","lifecycle"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/bloc_provider","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mono0926.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-29T06:52:27.000Z","updated_at":"2023-09-11T03:06:34.000Z","dependencies_parsed_at":"2022-08-16T02:50:41.003Z","dependency_job_id":null,"html_url":"https://github.com/mono0926/bloc_provider","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mono0926%2Fbloc_provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mono0926%2Fbloc_provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mono0926%2Fbloc_provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mono0926%2Fbloc_provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mono0926","download_url":"https://codeload.github.com/mono0926/bloc_provider/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mono0926%2Fbloc_provider/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259101701,"owners_count":22805323,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bloc","business-logic-component","dart","flutter","inherited-widget","lifecycle"],"created_at":"2024-12-10T16:17:19.212Z","updated_at":"2026-03-15T12:43:22.061Z","avatar_url":"https://github.com/mono0926.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bloc_provider [![Codemagic build status](https://api.codemagic.io/apps/5c07297ae5d85c000decbd7a/5c0b461ee3b238001782269a/status_badge.svg)](https://codemagic.io/apps/5c07297ae5d85c000decbd7a/5c0b461ee3b238001782269a/latest_build)\n\nProvides BLoC(Business Logic Component) to descendant widget (O(1)), and the bloc is disposed automatically by the state which the bloc_provider holds internally.\n\n## Recommended other packages\n\n`bloc_provider` was one of the good choice for BLoC pattern until early 2019, but I now recommend to use these instead.\n\n- [provider](https://pub.dev/packages/provider)\n- [disposable_provider](https://pub.dev/packages/disposable_provider)\n  - Thin wrapper of Provider and it calls dispose automatically.\n- [bloc](https://pub.dev/packages/bloc)\n- [riverpod](https://pub.dev/packages/riverpod)\n\n`bloc_provider` will now be minimally maintained.\n\n## Usage\n\n#### 1. Define some BLoC like this:\n\n```dart\nclass CounterBloc implements Bloc {\n  final _countController = BehaviorSubject\u003cint\u003e.seeded(0);\n  final _incrementController = PublishSubject\u003cvoid\u003e();\n\n  CounterBloc() {\n    _incrementController\n        .scan\u003cint\u003e((sum, _v, _i) =\u003e sum + 1, 0)\n        .pipe(_countController);\n  }\n\n  ValueStream\u003cint\u003e get count =\u003e _countController;\n  Sink\u003cvoid\u003e get increment =\u003e _incrementController.sink;\n\n  @override\n  void dispose() async {\n    await _incrementController.close();\n    await _countController.close();\n  }\n}\n```\n\n#### 2. Provide the bloc by using BlocProvider and access the bloc at subtree:\n\n```dart\nvoid main() =\u003e runApp(\n      // Create and provide the bloc.\n      BlocProvider\u003cCounterBloc\u003e(\n        creator: (_context, _bag) =\u003e CounterBloc(),\n        child: App(),\n      ),\n    );\n\nclass App extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    // Access the bloc with O(1) computation complexity.\n    final bloc = BlocProvider.of\u003cCounterBloc\u003e(context);\n    return MaterialApp(\n      home: Scaffold(\n        body: Center(\n          child: StreamBuilder\u003cint\u003e(\n            stream: bloc.count,\n            initialData: bloc.count.value,\n            builder: (context, snap) =\u003e Text(\n                  'count: ${snap.data}',\n                  style: Theme.of(context).textTheme.title,\n                ),\n          ),\n        ),\n        floatingActionButton: FloatingActionButton(\n          child: const Icon(Icons.add),\n          onPressed: () =\u003e bloc.increment.add(null),\n        ),\n      ),\n    );\n  }\n}\n```\n\n- Computational complexity of `of` method, which is used for accessing the bloc is `O(1)`.\n    - `of` method can be also called at [State](https://docs.flutter.io/flutter/widgets/State-class.html)'s [initState](https://docs.flutter.io/flutter/widgets/State/initState.html).\n- Provided bloc will be disposed when the inner state is disposed 👍\n\n\n## Examples\n\n- https://github.com/mono0926/bloc_provider/tree/master/example\n- [mono0926/wdb106-flutter](https://github.com/mono0926/wdb106-flutter)\n- [TaskShare/taskshare-flutter](https://github.com/TaskShare/taskshare-flutter)\n\n\n## Technical explanation\n\n- [Flutter の BLoC(Business Logic Component)のライフサイクルを正確に管理して提供する Provider パッケージの解説](https://medium.com/flutter-jp/bloc-provider-70e869b11b2f)\n  - Japanese only, currently🙇‍🇯🇵\n\n## Features and bugs\n\nPlease file feature requests and bugs at the [issue tracker][tracker].\n\n[tracker]: https://github.com/mono0926/bloc_provider/issues\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmono0926%2Fbloc_provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmono0926%2Fbloc_provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmono0926%2Fbloc_provider/lists"}