{"id":25272870,"url":"https://github.com/bewond/firebloc","last_synced_at":"2026-04-11T11:02:56.203Z","repository":{"id":217532686,"uuid":"264293823","full_name":"Bewond/firebloc","owner":"Bewond","description":"A small library to simplify the use of bloc to manage the states of simple queries to Firebase. (Currently in beta)","archived":false,"fork":false,"pushed_at":"2022-10-12T14:37:15.000Z","size":394,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-12T07:39:47.314Z","etag":null,"topics":["dart","firebase","flutter"],"latest_commit_sha":null,"homepage":"","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/Bewond.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-05-15T20:38:12.000Z","updated_at":"2023-11-15T06:06:37.000Z","dependencies_parsed_at":"2024-01-17T02:40:09.957Z","dependency_job_id":"4f96cb03-3a82-41ce-adcb-cc933a9cc202","html_url":"https://github.com/Bewond/firebloc","commit_stats":null,"previous_names":["bewond/firebloc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Bewond/firebloc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bewond%2Ffirebloc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bewond%2Ffirebloc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bewond%2Ffirebloc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bewond%2Ffirebloc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bewond","download_url":"https://codeload.github.com/Bewond/firebloc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bewond%2Ffirebloc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31677819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-11T08:18:19.405Z","status":"ssl_error","status_checked_at":"2026-04-11T08:17:08.892Z","response_time":54,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["dart","firebase","flutter"],"created_at":"2025-02-12T13:37:11.300Z","updated_at":"2026-04-11T11:02:56.185Z","avatar_url":"https://github.com/Bewond.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"/docs/assets/firebloc_dark.png\"\u003e\n    \u003cimg alt=\"Firebloc\" src=\"/docs/assets/firebloc.png\"\u003e\n  \u003c/picture\u003e\n\u003c/h1\u003e\n\n## Overview\n\nA small library for [Flutter](https://flutter.dev/) to simplify the use of [bloc](https://bloclibrary.dev/) to manage the states of simple queries to [Firebase](https://firebase.google.com/docs/firestore).\n\n(Currently in beta)\n\n- [Installing](#installing)\n- [Documentation](#documentation)\n  - [Example of BaseRepository](#example-of-baserepository)\n  - [Example with a custom repository](#example-with-a-custom-repository)\n  - [Advanced use case](#advanced-use-case)\n- [Useful widgets and functions](#useful-widgets-and-functions)\n  - [Firebloc Widgets](#firebloc-widgets)\n  - [Firebloc Utilities](#firebloc-utilities)\n- [Maintainers](#maintainers)\n\n## Installing\n\n#### Depend\n\nAdd this to your package's pubspec.yaml file:\n\n```yaml\ndependencies:\n  firebloc:\n    git:\n      url: git://github.com/bewond/firebloc.git\n      path: firebloc\n```\n\n#### Install\n\nYou can install packages from the command line:\n\n```shell\nflutter pub get\n```\n\n## Documentation\n\n### Example of BaseRepository\n\nThis example shows how to use BaseRepository to retrieve data from a collection by creating only the data model.\n\n**Data model** (`disocverLabel.dart`):\n\n```dart\nimport 'package:meta/meta.dart';\n\nimport 'package:firebloc/firebloc.dart';\nimport 'package:cloud_firestore/cloud_firestore.dart';\n\n\nclass DiscoverLabel extends FireblocData {\n  final String text;\n  final String description;\n\n  DiscoverLabel({\n    @required this.text,\n    @required this.description,\n  });\n\n  @override\n  Map\u003cString, Object\u003e toDocument() {\n    return {\n      \"text\": text,\n      \"description\": description,\n    };\n  }\n\n  //\n\n  static DiscoverLabel fromSnapshot(DocumentSnapshot snap) {\n    return DiscoverLabel(\n      text: snap.data['text'],\n      description: snap.data['description'],\n    );\n  }\n}\n```\n\nClasses representing data models must extend from `FireblocData`.\nWe recommend implementing a static method `fromSnapshot` within the model.\n\n**Using the bloc**:\n\n```dart\nBlocProvider\u003cFirebloc\u003e(\n  create: (context) =\u003e Firebloc\u003cDiscoverLabel\u003e(\n    repository: BaseRepository\u003cDiscoverLabel\u003e(\n      collectionName: 'mainLabels', //The collection from which to recover data.\n      fromSnapshot: DiscoverLabel.fromSnapshot, //Static method implemented in the model.\n    ),\n  ),\n  child: BlocBuilder\u003cFirebloc, FireblocState\u003e(\n    builder: (context, state) {\n      //Fetch data.\n      if (state is Starting)\n        BlocProvider.of\u003cFirebloc\u003e(context).add(FetchData());\n\n      //Access to data.\n      if (state is Success) {\n        DiscoverLabel firstLabel = state.data[0];\n        print(firstLabel.text);\n        print(firstLabel.description);\n\n        return Text('Success');\n      }\n\n      //Loading indicator.\n      else if (state is Loading)\n        return CircularProgressIndicator();\n\n      //Error message.\n      else\n        return Text('Error');\n    },\n  ),\n)\n```\n\n### Example with a custom repository\n\nWhen the query to be executed is more complex, a customized repository and data model can be created. \\\nThe classes that represent repositories must extend from `FireblocRepository`\nand specify the custom type of data model you intend to use.\n\nThe model is the same as in the previous example (`disocverLabel.dart`).\n\n**Data Repository** (`discoverRepository.dart`):\n\n```dart\nimport 'package:firebloc/firebloc.dart';\nimport 'package:cloud_firestore/cloud_firestore.dart';\n\nimport 'package:bddelivery/models/discoverLabel.dart';\n\n\nclass DiscoverRepository extends FireblocRepository\u003cDiscoverLabel\u003e {\n  final _collection = FirebaseFirestore.instance.collection('mainLabels');\n\n  @override\n  Stream\u003cList\u003cDiscoverLabel\u003e\u003e getData() {\n    return _collection.snapshots().map((snapshot) {\n      return snapshot.docs\n          .map((doc) =\u003e DiscoverLabel.fromSnapshot(doc))\n          .toList();\n    });\n  }\n}\n```\n\nThe use of the bloc is very similar to the previous example,\njust modify the repository definition to use the custom one.\n\n**Using the bloc**:\n\n```dart\nBlocProvider\u003cFirebloc\u003e(\n  create: (context) =\u003e Firebloc\u003cDiscoverLabel\u003e(\n    repository: DiscoverRepository(),\n  ),\n  child: BlocBuilder\u003cFirebloc, FireblocState\u003e(\n    builder: (context, state) {\n      //...\n    },\n  ),\n)\n```\n\n### Advanced use case\n\n**Custom Bloc with custom repository**: \\\nJust define the new events you want to use, the events and base states are contained in Firebloc. \\\nHowever, it is still necessary to map all the events used in the bloc, including those contained in Firebloc, in particular UpdateData. \\\nIn this case it is no longer necessary for the repository to extend from `FireblocRepository`.\n\n## Useful widgets and functions\n\nFirebloc provides some tools to make coding more efficient and concise.\n\n### Firebloc Widgets\n\n**FireblocBuilder**: \\\n`FireblocBuilder` A BlocBuilder wrapper to simplify its use with Firebloc.\nIf a function for a specific state is not defined, it returns optional parameter `defaultWidget`.\n\n```dart\nFireblocBuilder\u003cDiscoverLabel\u003e(\n  starting: (context) {\n    BlocProvider.of\u003cFirebloc\u003e(context).add(FetchData());\n    return Container();\n  },\n  success: (List\u003cDiscoverLabel\u003e data) {\n    if (data.isNotEmpty)\n      return Text('Success: ${data.length}');\n    else\n      return Text('Page not found');\n  },\n)\n```\n\n### Firebloc Utilities\n\n**stateToWidget**: \\\n`FireblocUtilities.stateToWidget`\nA function to simplify the writing of the code when you need to return a different Widget depending on the FireblocState.\nYou must also specify the data type, in this case `DiscoverLabel`, to make the type explicit in the `success` function.\n\n```dart\nBlocProvider\u003cFirebloc\u003e(\n  create: (context) =\u003e Firebloc\u003cDiscoverLabel\u003e(\n    repository: BaseRepository\u003cDiscoverLabel\u003e(\n      collectionName: 'mainLabels',\n      fromSnapshot: DiscoverLabel.fromSnapshot,\n    ),\n  ),\n  child: BlocBuilder\u003cFirebloc, FireblocState\u003e(\n    builder: (context, state) =\u003e FireblocUtilities.stateToWidget\u003cDiscoverLabel\u003e(\n      context,\n      state,\n      starting: (context) {\n        BlocProvider.of\u003cFirebloc\u003e(context).add(FetchData());\n        return Container();\n      },\n      success: (data) {\n        DiscoverLabel firstLabel = data[0];\n        print(firstLabel.text);\n        print(firstLabel.description);\n\n        return Text('Success');\n      },\n      loading: () =\u003e CircularProgressIndicator(),\n      error: () =\u003e Text('Error'),\n    ),\n  ),\n)\n```\n\nIf necessary, you can specify a default Widget using the optional `defaultWidget` parameter.\n\n---\n\n## Maintainers\n\n- [Riccardo Brero](https://github.com/Riki1312)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbewond%2Ffirebloc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbewond%2Ffirebloc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbewond%2Ffirebloc/lists"}