{"id":16401902,"url":"https://github.com/festelo/hew","last_synced_at":"2025-08-23T13:34:04.947Z","repository":{"id":104893281,"uuid":"601838072","full_name":"festelo/hew","owner":"festelo","description":null,"archived":false,"fork":false,"pushed_at":"2023-03-30T18:36:18.000Z","size":314,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T15:46:02.187Z","etag":null,"topics":[],"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/festelo.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-14T23:39:42.000Z","updated_at":"2023-02-14T23:40:07.000Z","dependencies_parsed_at":"2023-07-11T07:32:58.516Z","dependency_job_id":null,"html_url":"https://github.com/festelo/hew","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/festelo/hew","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/festelo%2Fhew","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/festelo%2Fhew/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/festelo%2Fhew/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/festelo%2Fhew/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/festelo","download_url":"https://codeload.github.com/festelo/hew/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/festelo%2Fhew/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271749051,"owners_count":24814115,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-10-11T05:44:29.219Z","updated_at":"2025-08-23T13:34:04.923Z","avatar_url":"https://github.com/festelo.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp\u003e\n\u003ca href=\"https://github.com/festelo/hew/actions\"\u003e\u003cimg src=\"https://github.com/festelo/hew/actions/workflows/tests.yml/badge.svg\" alt=\"Build \u0026 Test\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/festelo/hew\"\u003e\u003cimg src=\"https://codecov.io/gh/festelo/hew/branch/main/graph/badge.svg\" alt=\"codecov\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/mit\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-blue.svg\" alt=\"License: MIT\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Hew\n\nHew is a simple and fast library that helps you organize your Flutter app's presentation layer.  \n\nIt's inspired by `StateNotifier` from [Riverpod](https://riverpod.dev/)  and `Cubit` from [bloc](https://pub.dev/packages/bloc), and introduces two new entities: `Presenter` and `PresentationModel`.  \n  \nIt's worth noting that `Cubit` is designed to be used in the domain layer, whereas `hew` is meant to be used exclusively in the presentation layer.  \n\nThe goal of this library is to provide a convenient way to split `StatefulWidget`s into three distinct parts:  `Model`, `Presenter` and `Widget`. By doing so, you can easily test your `Presenter` and `Model` without having to worry about `Widget` itself. Additionally, it separates your presentation logic from your view logic and makes your code easier to maintain.\n\n## Configuring\n\nAdd `hew` to your `pubspec.yaml` file:\n\n```yaml\ndependencies:\n  hew: ^0.0.1\n```\n\n## Usage\n\n### Presenter\n\nPresenter is a class that contains all the logic of your widget.\n\nThe presenter is responsible for updating a model of the widget, and the widget is responsible for displaying the model.\n\nLet's look at the counter presenter example:\n\n```dart\nclass CounterPresenter extends Presenter\u003cCounterModel\u003e {\n  CounterPresenter() : super(CounterModel());\n\n  void onIncreaseCounterTap() =\u003e notify(() =\u003e model.counter++);\n}\n```\n\nHere we have a simple presenter that creates `CounterModel` and increases counter by one on `onIncreaseCounterTap` call.\n\n### Model\n\nModel is a class that contains all data we want to be displayed in the widget.\n\nLet's create a simple model for our previous presenter:\n\n```dart\nclass CounterModel with MutableEquatableMixin {\n  int counter = 0;\n\n  @override\n  List\u003cObject?\u003e get mutableProps =\u003e [counter];\n}\n```\n\nThe model contains only one field - `counter`, the value we want to display.  \n  \nIt also mixes in `MutableEquatableMixin` and overrides `mutableProps` getter.  \nYou should pass all your mutable fields to `mutableProps` getter to make `Presenter` behave correctly.  \n  \n`MutableEquatableMixin` is a mixin that adds `mutableHashCode` to the model. This is an integer generated based on hashCodes of fields you pass to `mutableProps`.  \n  \nPresenter uses `mutableHashCode` to make `notify` method notify its listeners only if there're any changes in model.\n\n### Widget\n\nNow it's time to display our model.\n\nWe can do this by using `PresenterWidget`, `PresenterStatefulWidget` or by using `PresenterBuilder`. \n\nLet's look how the first approach works:\n\n```dart\nclass Counter extends PresenterWidget\u003cCounterPresenter, CounterModel\u003e {\n  const Counter({Key? key}) : super(key: key);\n\n  @override\n  CounterPresenter createPresenter() =\u003e CounterPresenter();\n\n  @override\n  Widget build(context, presenter, model) {\n    return TextButton(\n      onPressed: presenter.onIncreaseCounterTap,\n      child: Text(model.counter.toString()),\n    );\n  }\n}\n```\n\nHere we display the counter value inside `TextButton` and call `onIncreaseCounterTap` on `onPressed` event.   \n`PresenterWidget` maintains `Presenter` lifecycle and supports automatic rebuilding on `model` change.\n  \nBut sometimes we need to implement something more complex and in flutter we usually do it by using `StatefulWidget`. `Hew` has `PresenterStatefulWidget` for this:  \n\n\n```dart\nclass Counter extends PresenterStatefulWidget\u003cCounterPresenter\u003e {\n  const Counter({super.key});\n\n  @override\n  CounterPresenter createPresenter() =\u003e CounterPresenter();\n\n  @override\n  PresenterState createState() =\u003e _CounterState();\n}\n\nclass _CounterState\n    extends PresenterState\u003cCounterPresenter, CounterModel, Counter\u003e {\n  @override\n  Widget build(BuildContext context) {\n    return TextButton(\n      onPressed: presenter.onIncreaseCounterTap,\n      child: Text(model.counter.toString()),\n    );\n  }\n}\n```\n\nAnd if you want to be more flexible, you can use `PresenterBuilder`:\n\n```dart\nclass Counter extends StatelessWidget {\n  const Counter({Key? key}) : super(key: key);\n\n  @override\n  Widget build(BuildContext context) {\n    return PresenterBuilder\u003cCounterPresenter, CounterModel\u003e(\n      resolver: () =\u003e CounterPresenter(),\n      builder: (context, presenter, model) =\u003e TextButton(\n        onPressed: presenter.onIncreaseCounterTap,\n        child: Text(model.counter.toString()),\n      ),\n    );\n  }\n}\n\n```\n\n### ModelObserver\n\nAll previous approaches by default automatically rebuild themself whenever the model changes. If you want to handle state changes manually, you can disable this behaviour and use `ModelObserver`.\n\nTo disable automatic rebuilding, you can pass `false` to `rebuildOnChanges` parameter of `PresenterBuilder`, or override `rebuildOnChanges` getter in your `PresenterWidget` and `PresenterStatefulWidget`:\n\n```dart\nclass Counter extends PresenterWidget\u003cCounterPresenter\u003e {\n  bool get rebuildOnChanges =\u003e false;\n  ...\n}\n\n// or\n\n@override\nWidget build(BuildContext context) {\n  return PresenterBuilder\u003cCounterPresenter, CounterModel\u003e(\n    rebuildOnChanges: false,\n    resolver: () =\u003e CounterPresenter(),\n    builder: (context, presenter, model) =\u003e TextButton(\n      onPressed: presenter.onIncreaseCounterTap,\n      child: Text(model.counter.toString()),\n    ),\n  );\n}\n```\n\nThen you should use `ModelObserver` to track model changes:\n\n```dart\n@override\nWidget build(context, presenter, model) {\n  return ModelObserver(\n    presenter: presenter,\n    builder: (context) =\u003e TextButton(\n      onPressed: presenter.onIncreaseCounterATap,\n      child: Text(model.counter.toString()),\n    ),\n  );\n}\n```\n\nIf you want to rebuild your widget only when changes are in some specific field, you can use `when` parameter, just specify a path to the field:  \n`when: (model) =\u003e model.counterB`.   \n\nIf there are multiple fields, you can pass a list of fields as well:  \n`when: (model) =\u003e [model.counterA, model.counterB]`.\n\n## Expansions\n\nTBD","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffestelo%2Fhew","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffestelo%2Fhew","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffestelo%2Fhew/lists"}