{"id":19648952,"url":"https://github.com/frideosapps/rebuilder","last_synced_at":"2025-04-28T16:30:32.515Z","repository":{"id":56837970,"uuid":"189488692","full_name":"frideosapps/rebuilder","owner":"frideosapps","description":"An easy and minimalistic state management for flutter.","archived":false,"fork":false,"pushed_at":"2019-06-08T16:47:29.000Z","size":91,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T09:33:43.847Z","etag":null,"topics":["flutter","flutter-apps","flutter-examples","flutter-state-management","state-management","widgets"],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frideosapps.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":"2019-05-30T22:07:22.000Z","updated_at":"2021-02-26T08:07:58.000Z","dependencies_parsed_at":"2022-09-12T10:20:10.202Z","dependency_job_id":null,"html_url":"https://github.com/frideosapps/rebuilder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frideosapps%2Frebuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frideosapps%2Frebuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frideosapps%2Frebuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frideosapps%2Frebuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frideosapps","download_url":"https://codeload.github.com/frideosapps/rebuilder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251345735,"owners_count":21574766,"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":["flutter","flutter-apps","flutter-examples","flutter-state-management","state-management","widgets"],"created_at":"2024-11-11T14:51:02.826Z","updated_at":"2025-04-28T16:30:31.662Z","avatar_url":"https://github.com/frideosapps.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rebuilder [![pub package](https://img.shields.io/pub/v/rebuilder.svg)](https://pub.dartlang.org/packages/rebuilder)\n\n**Rebuilder** is an easy and minimalistic state management library for Flutter. \n\nIt consists of:\n\n- A `DataModel` class to extend to create a class where lives the data and the business logic for the UI.\n  \n- A `DataModelProvider` that provides this model to the widgets tree by using an InheritedWidget.\n  \n- A `RebuilderState` that holds the state of a `Rebuilder` widget.\n  \n- The `Rebuilder` widget that represents the entity which rebuilds every time the `rebuild` method of the associated `RebuilderState`'s `state` property is called. \n  \n- The `RebuilderObject`: an object bound to a `RebuilderState` in order to rebuild the `Rebuilder` widget associated to this state whenever a new value is set.\n  \n\n##### Examples built with this library:\n- **[Rebuilder example](https://github.com/frideosapps/rebuilder/tree/master/example)**. Check out the example app to know how to: \n  - Implement a counter\n  - Use the DataModel to separate the UI from the business logic\n  - Implement a dynamic theme changer with a `RebuilderObject`\n  - Bind a function to a `RebuilderObject`\n  - Sharing data between widgets\n  - Update only a subtree of widgets\n  \n- **[Quiz game](https://github.com/frideosapps/trivia_rebuilder)**: a simple trivia game built with Flutter and this package.\n\n\n\n## Getting started\n\n\n##### 1. Define a `DataModel`\n```dart\nclass CountersModel extends DataModel {\n  CountersModel() {\n\n    // Initialize the instance of the `RebuilderObject` with\n    // with an instance of a `RebuilderState` that will be bound\n    // to a `Rebuilder` widget.\n    counterDown = RebuilderObject\u003cint\u003e.init(\n        rebuilderState: counterDownState,\n        initialData: 100,\n        onChange: _onCounterDownChange);\n  }\n  \n  // STATES\n  final counterUpState = RebuilderState();\n  final counterDownState = RebuilderState();\n  final counterMulState = RebuilderState(); \n\n  // COUNTERS\n  int counterUp = 0;\n  int counterMul = 2;\n  RebuilderObject\u003cint\u003e counterDown;\n\n  // METHODS\n  void incrementCounterUp() {\n    counterUp++;\n    counterUpState.rebuild();\n  }\n\n  void decrementCounterDown() {\n    counterDown.value--;\n\n    // Using the `RebuilderObject` the `rebuild` method of the\n    // counterDownState will automatically be called.\n    //\n    // states.counterDownState.rebuild();\n  }\n\n  void _onCounterDownChange() {\n    print('Value changed: ${counterDown.value}');\n  }\n\n  @override\n  void dispose() {}\n}\n```\n\n##### 2. Provide the `CountersModel` by using the `DataModelProvider` widget\n```dart\nfinal countersModel = CountersModel()\n\nDataModelProvider\u003cCountersModel\u003e(\n          dataModel: countersModel,\n          child: const CountersPage(),\n);\n```\n\n\n##### 3. Get the `CountersModel` instance from the `context` of a widget in the tree\n```dart\n  Widget build(BuildContext context) {\n    final countersModel = DataModelProvider.of\u003cCountersModel\u003e(context);\n```\n\n\n##### 4. Bind the `RebuilderState` instances to the `Rebuilder` widgets in the view\n```dart\nRebuilder\u003cCountersModel\u003e(\n    dataModel: countersModel,\n    rebuilderState: countersModel.counterUpState,\n    builder: (state, data) {\n      // Accessing to `counterUp` in the `DataModel`\n      // derived class provided through the `data` parameter\n      return Text('${data.counterUp}');\n      // \n      // It is possible to directly access to `counterUp`\n      // without using the `dataModel` parameter:\n      //\n      // builder: (state, _) {\n      // return Text('${countersModel.counterUp}');\n    }),\nRaisedButton(\n  child: const Text('+'),\n  onPressed: countersModel.incrementCounterUp,\n),\n\n\n \nRebuilder\u003cRebuilderObject\u003e(\n  dataModel: countersModel.counterDown,\n  rebuilderState: countersModel.counterDownState,\n  builder: (state, data) {\n    return Text('${data.value}');\n  }),\nRaisedButton(\n  child: const Text('-'),\n  onPressed: countersModel.decrementCounterDown,\n)\n\n\n\nRebuilder\u003cCountersModel\u003e(\n  dataModel: countersModel,\n  rebuilderState: countersModel.counterMulState,\n  builder: (state, data) {\n    return Column(children: \u003cWidget\u003e[\n      Text('${data.counterMul}'),\n      RaisedButton(\n          child: const Text('*'),\n          onPressed: () {\n            data.counterMul *= 2;\n            if (data.counterMul \u003e 65536) {\n              data.counterMul = 2;\n            }\n            state.rebuild();                                          \n            }),\n    ]);\n  }),\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrideosapps%2Frebuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrideosapps%2Frebuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrideosapps%2Frebuilder/lists"}