{"id":16583688,"url":"https://github.com/aloisdeniel/built_bloc","last_synced_at":"2025-03-21T12:33:08.592Z","repository":{"id":56826781,"uuid":"165812494","full_name":"aloisdeniel/built_bloc","owner":"aloisdeniel","description":"Generate the BLoC pattern boilerplate.","archived":false,"fork":false,"pushed_at":"2020-10-27T15:05:37.000Z","size":122,"stargazers_count":51,"open_issues_count":6,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T01:40:36.510Z","etag":null,"topics":["bloc","dart","flutter","generator","pattern"],"latest_commit_sha":null,"homepage":null,"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/aloisdeniel.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-01-15T08:21:45.000Z","updated_at":"2021-06-29T10:56:05.000Z","dependencies_parsed_at":"2022-09-20T22:02:02.652Z","dependency_job_id":null,"html_url":"https://github.com/aloisdeniel/built_bloc","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aloisdeniel%2Fbuilt_bloc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aloisdeniel%2Fbuilt_bloc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aloisdeniel%2Fbuilt_bloc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aloisdeniel%2Fbuilt_bloc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aloisdeniel","download_url":"https://codeload.github.com/aloisdeniel/built_bloc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244799593,"owners_count":20512281,"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","dart","flutter","generator","pattern"],"created_at":"2024-10-11T22:42:51.887Z","updated_at":"2025-03-21T12:33:08.101Z","avatar_url":"https://github.com/aloisdeniel.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# built_bloc \n\nGenerate the BLoC pattern boilerplate.\n\n## Why ?\n\nAfter using the [BLoC pattern](https://medium.com/flutter-io/build-reactive-mobile-apps-in-flutter-companion-article-13950959e381) a little, it seems pretty cool for sharing code and separation of concerns, but I quickly found myself to write a **lot of repetitive boilerplate code** : I felt the need for a generator to assist me.\n\nHere is a simple vanilla bloc example which obviously highlights repeated patterns while declaring subjects, streams, sinks and subscriptions.\n\n```dart\nclass VanillaExampleBloc {\n\n  Sink\u003cvoid\u003e get reset =\u003e this._reset.sink;\n\n  Sink\u003cint\u003e get add =\u003e this._add.sink;\n\n  Stream\u003cint\u003e get count =\u003e this._count.stream;\n\n  final PublishSubject\u003cint\u003e _add = PublishSubject\u003cint\u003e();\n\n  final PublishSubject\u003cvoid\u003e _reset = PublishSubject\u003cvoid\u003e();\n\n  final BehaviorSubject\u003cint\u003e _count = BehaviorSubject\u003cint\u003e.seeded(0);\n\n  List\u003cStreamSubscription\u003e subscriptions;\n\n  List\u003cSubject\u003e subjects;\n\n  VanillaExampleBloc() {\n    subscriptions = [\n      this._add.listen(_onAdd),\n      this._reset.listen(_onReset),\n    ];\n    subjects = [\n      this._add,\n      this._count,\n      this._reset,\n    ];\n  }\n\n  void _onAdd(int value) {\n    this._count.add(this._count.value + value);\n  }\n\n  void _onReset(int value) {\n    this._count.add(0);\n  }\n\n  @mustCallSuper\n  void dispose() {\n    this.subjects.forEach((s) =\u003e s.close());\n    this.subscriptions.forEach((s) =\u003e s.cancel());\n  }\n}\n```\n\nWith **built_bloc**, you can replace all of that with just a few lines of code :\n\n```dart\n@bloc\nclass ExampleBloc extends Bloc with _ExampleBloc {\n  @stream\n  final BehaviorSubject\u003cint\u003e _count = BehaviorSubject\u003cint\u003e(seedValue: 0);\n\n  @sink\n  @Bind(\"_onAdd\")\n  final PublishSubject\u003cint\u003e _add = PublishSubject\u003cint\u003e();\n\n  @sink\n  @Bind(\"_onReset\")\n  final PublishSubject\u003cvoid\u003e _reset = PublishSubject\u003cvoid\u003e();\n\n  void _onAdd(int value) {\n    this._count.add(this._count.value + value);\n  }\n\n  void _onReset() {\n    this._count.add(0);\n  }\n}\n```\n\n## How to use ?\n\nSee the [built_bloc_generator](https://pub.dartlang.org/packages/built_bloc_generator) package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faloisdeniel%2Fbuilt_bloc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faloisdeniel%2Fbuilt_bloc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faloisdeniel%2Fbuilt_bloc/lists"}