{"id":24377749,"url":"https://github.com/aissat/unistate_tuto","last_synced_at":"2026-04-09T07:53:34.194Z","repository":{"id":269353767,"uuid":"906459734","full_name":"aissat/unistate_tuto","owner":"aissat","description":"App demonstrating various state management techniques by #Unistate","archived":false,"fork":false,"pushed_at":"2024-12-25T12:18:35.000Z","size":363,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T06:17:51.187Z","etag":null,"topics":["bloc","cubit","cubit-bloc","dart","flutter","flutter-clean-architecture","flutter-community","flutter-demo","flutter-examples","flutter-state-management","flutter-tutorial","getx","listener","notifier","provider","solidart","state-management"],"latest_commit_sha":null,"homepage":"https://github.com/aissat/unistate","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aissat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-12-21T00:56:55.000Z","updated_at":"2025-01-01T15:35:33.000Z","dependencies_parsed_at":"2024-12-23T00:36:24.837Z","dependency_job_id":"88a8632b-568c-44c1-94fa-dfc7b3582963","html_url":"https://github.com/aissat/unistate_tuto","commit_stats":null,"previous_names":["aissat/unistate_app"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aissat%2Funistate_tuto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aissat%2Funistate_tuto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aissat%2Funistate_tuto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aissat%2Funistate_tuto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aissat","download_url":"https://codeload.github.com/aissat/unistate_tuto/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243222184,"owners_count":20256220,"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","cubit","cubit-bloc","dart","flutter","flutter-clean-architecture","flutter-community","flutter-demo","flutter-examples","flutter-state-management","flutter-tutorial","getx","listener","notifier","provider","solidart","state-management"],"created_at":"2025-01-19T06:16:52.599Z","updated_at":"2025-12-26T07:59:43.088Z","avatar_url":"https://github.com/aissat.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unistate App\n\nThis is a Flutter application demonstrating various state management techniques.\n\n## State Management Implementations\n\nThe application includes the following state management implementations:\n\n- CounterBloc\n- CounterCubit\n- CounterProvider\n- CounterGetx\n\n## Getting Started\n\nTo run the application, use the following command:\n\n```sh\nflutter run\n```\n\n## Adding a New State Management Implementation\n\nTo add a new state management implementation, follow these steps:\n\n1. Create a new state management class in the `lib/counter/state` directory.\n2. Export the new class in `lib/counter/state/counter.dart`.\n3. Add an instance of the new class to the `MultiUniState` widget in `lib/main.dart`.\n\n## Screenshots\n\n| bloc                                                                                   | cubit                                                                                    | getx                                                                                   | provider                                                                                       |\n| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |\n| ![bloc](https://raw.githubusercontent.com/aissat/unistate_app/main/screenshots/bloc.png) | ![cubit](https://raw.githubusercontent.com/aissat/unistate_app/main/screenshots/cubit.png) | ![getx](https://raw.githubusercontent.com/aissat/unistate_app/main/screenshots/getx.png) | ![provider](https://raw.githubusercontent.com/aissat/unistate_app/main/screenshots/provider.png) |\n\n## CounterGetx\n\nThe `CounterGetx` class uses the GetX package for state management. It is implemented as follows:\n\n```dart\nimport 'package:get/get.dart';\nimport 'package:unistate_adapter/unistate_adapter.dart';\n\nimport 'abstract.dart';\n\nclass CounterGetx extends GetxController\n    with UnistateGetxMixin\u003cint\u003e\n    implements Counter {\n  CounterGetx() {\n    initState(0);\n  }\n\n  @override\n  void decrement() {\n    value--;\n  }\n\n  @override\n  void increment() {\n    value++;\n  }\n}\n```\n\n## CounterBloc\n\nThe `CounterBloc` class uses the Bloc package for state management. It is implemented as follows:\n\n```dart\nimport 'package:flutter_bloc/flutter_bloc.dart';\nimport 'package:unistate_adapter/unistate_adapter.dart';\n\nimport 'abstract.dart';\n\nclass CounterBloc extends Bloc\u003cCounterEvent, int\u003e implements Counter {\n  CounterBloc() : super(0) {\n    on\u003cIncrementEvent\u003e((event, emit) =\u003e emit(state + 1));\n    on\u003cDecrementEvent\u003e((event, emit) =\u003e emit(state - 1));\n  }\n\n  @override\n  void decrement() {\n    add(DecrementEvent());\n  }\n\n  @override\n  void increment() {\n    add(IncrementEvent());\n  }\n}\n\nabstract class CounterEvent {}\n\nclass IncrementEvent extends CounterEvent {}\n\nclass DecrementEvent extends CounterEvent {}\n```\n\nMake sure to add `Counter[State]` to the `MultiUniState` widget in `lib/main.dart`:\n\n```dart\n// filepath: /home/aye7/Workspace/me/unistate_app/lib/main.dart\nvoid main() {\n  runApp(MultiUniState(notifiers: [\n    CounterBloc(),\n    CounterCubit(),\n    CounterProvider(),\n    CounterGetx(), // Add the new state management implementation here\n  ], child: MyApp()));\n}\n```\n\n## UnistateListenableMixin\n\n`UnistateListenableMixin` is a mixin that provides a way to listen to state changes and notify listeners. It is used in conjunction with state management controllers to provide a reactive programming model.\n\n### Why Use UnistateListenableMixin?\n\nThe `UnistateListenableMixin` simplifies the process of creating reactive state management solutions by providing a consistent way to notify listeners about state changes. This mixin abstracts away the boilerplate code required to manage listeners, making your code cleaner and easier to maintain.\n\n### Benefits\n\n- **Consistency**: Provides a consistent way to manage state changes across different state management solutions.\n- **Simplicity**: Reduces boilerplate code by handling listener notifications automatically.\n- **Reusability**: Can be reused across different state management controllers, promoting code reuse.\n- **Maintainability**: Makes the codebase easier to maintain by centralizing the listener notification logic.\n- **Flexibility**: Supports any state management solution, making it easy to integrate with various state management libraries.\n\n### Usage\n\nTo use `UnistateListenableMixin`, you need to create a class that mixes it in and implements the `CounterListenable` abstract class. Here is an example:\n\n```dart\nimport 'package:unistate_adapter/unistate_adapter.dart';\n\nabstract class CounterListenable\u003cT\u003e with UnistateListenableMixin\u003cT\u003e {\n  void decrement();\n  void increment();\n}\n```\n\n### Example\n\nHere is an example of how to use `UnistateListenableMixin` with a GetX controller:\n\n```dart\nimport 'package:unistate_adapter/unistate_adapter.dart';\nimport 'counter_getx_ctl.dart';\nimport 'icounter_listenable.dart';\n\nclass CounterGetxListenable extends CounterListenable\u003cCounterGetxCtl\u003e {\n  final _ctl = CounterGetxCtl();\n\n  @override\n  CounterGetxCtl get value =\u003e _ctl;\n\n  @override\n  void decrement() {\n    value.decrement();\n    notifyListeners();\n    print('CounterGetx: $value');\n  }\n\n  @override\n  void increment() {\n    value.increment();\n    notifyListeners();\n    print('CounterGetx: $value');\n  }\n}\n```\n\nAnd here is an example with a Solidart controller:\n\n```dart\nimport 'package:unistate_adapter/unistate_adapter.dart';\nimport 'counter_solid_ctl.dart';\nimport 'icounter_listenable.dart';\n\nclass CounterSolidListenable extends CounterListenable\u003cCounterSolidCtl\u003e {\n  final _ctl = CounterSolidCtl();\n\n  @override\n  CounterSolidCtl get value =\u003e _ctl;\n\n  @override\n  void decrement() {\n    _ctl.decrement();\n    notifyListeners();\n  }\n\n  @override\n  void increment() {\n    _ctl.increment();\n    notifyListeners();\n  }\n}\n```\n\nIn both examples, the `notifyListeners` method is called after the state is modified to notify any listeners about the change.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faissat%2Funistate_tuto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faissat%2Funistate_tuto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faissat%2Funistate_tuto/lists"}