{"id":20664004,"url":"https://github.com/flutterando/value_notifier_plus","last_synced_at":"2025-04-19T16:10:26.349Z","repository":{"id":247693762,"uuid":"826581169","full_name":"Flutterando/value_notifier_plus","owner":"Flutterando","description":"ValueNotifierPlus é um pacote que expande as funcionalidades de ValueNotifier do Flutter.","archived":false,"fork":false,"pushed_at":"2024-09-26T20:20:41.000Z","size":344,"stargazers_count":3,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T09:51:17.209Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/value_notifier_plus","language":"C++","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/Flutterando.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":"2024-07-10T01:52:55.000Z","updated_at":"2025-01-06T01:00:07.000Z","dependencies_parsed_at":"2024-11-16T21:17:33.770Z","dependency_job_id":null,"html_url":"https://github.com/Flutterando/value_notifier_plus","commit_stats":null,"previous_names":["flutterando/value_notifier_plus"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flutterando%2Fvalue_notifier_plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flutterando%2Fvalue_notifier_plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flutterando%2Fvalue_notifier_plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Flutterando%2Fvalue_notifier_plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Flutterando","download_url":"https://codeload.github.com/Flutterando/value_notifier_plus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249734065,"owners_count":21317694,"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":[],"created_at":"2024-11-16T19:21:35.393Z","updated_at":"2025-04-19T16:10:26.305Z","avatar_url":"https://github.com/Flutterando.png","language":"C++","readme":"# Value Notifier Plus\n\n[![License: MIT][license_badge]][license_link]\n\n`ValueNotifierPlus` é um pacote que expande as funcionalidades de `ValueNotifier` do Flutter, oferecendo uma alternativa ao `Cubit` utilizando `ValueNotifier` em vez de `Streams`. `ValueNotifier` é mais eficiente em termos de desempenho porque não precisa lidar com a complexidade de um sistema de fluxo assíncrono. Isso pode ser importante em cenários de alta frequência de atualização de UI.\n\n## Instalação\n\nAdicione o `ValueNotifierPlus` ao seu arquivo `pubspec.yaml`:\n\n```yaml\ndependencies:\n  value_notifier_plus: ^x.x.x\n```\n\n## O que é o `ValueNotifierPlus`\n\nO `ValueNotifierPlus` é uma classe que estende o `ValueNotifier` padrão do Flutter, adicionando capacidades adicionais como estados imutáveis e integração simplificada com a árvore de widgets. Ele facilita o gerenciamento de estado de forma mais eficiente e menos verbosa, sem a necessidade de streams e eventos complexos.\n\n## Widgets do `ValueNotifierPlus`\n\n### `BuilderPlus`\n\nO `BuilderPlus` é um widget que reconstrói sua árvore de widgets sempre que o valor do `ValueNotifierPlus` muda. É similar ao `BlocBuilder` do pacote `flutter_bloc`.\n\n#### Exemplo de Uso:\n\n```dart\nimport 'package:flutter/material.dart';\nimport 'value_notifier_plus.dart';\n\nclass CounterNotifier extends ValueNotifierPlus\u003cint\u003e {\n  CounterNotifier() : super(0);\n\n  void increment() =\u003e emit(state + 1);\n  void decrement() =\u003e emit(state - 1);\n}\n\nvoid main() {\n  runApp(MyApp());\n}\n\nclass MyApp extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return PlusProvider(\n      provider: CounterNotifier(),\n      child: MaterialApp(\n        home: CounterPage(),\n      ),\n    );\n  }\n}\n\nclass CounterPage extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    final counterNotifier = context.of\u003cCounterNotifier\u003e();\n\n    return Scaffold(\n      appBar: AppBar(title: Text('ValueNotifierPlus Example')),\n      body: Center(\n        child: BuilderPlus\u003cCounterNotifier, int\u003e(\n          notifier: counterNotifier,\n          builder: (context, state) {\n            return Text('Counter: $state');\n          },\n        ),\n      ),\n      floatingActionButton: FloatingActionButton(\n        onPressed: counterNotifier.increment,\n        child: Icon(Icons.add),\n      ),\n    );\n  }\n}\n```\n\n**Para controlar com precisão quando a função `builder` é chamada, pode-se fornecer opcionalmente um `buildWhen`. O `buildWhen` recebe o estado anterior e o estado atual do `ValueNotifierPlus` e retorna um booleano. Se `buildWhen` retornar verdadeiro, `builder` será chamado com o `state` e o widget será reconstruído. Se `buildWhen` retornar falso, `builder` não será chamado com o `state` e nenhuma reconstrução ocorrerá.**\n\n```dart\nBuilderPlus\u003cCounterNotifier, int\u003e(\n  notifier: counterNotifier,\n  buildWhen: (previousState, state) {\n    // retorna true/false para determinar quando\n    // reconstruir o widget com o novo estado.\n    return state \u003e previousState + 2;\n  },\n  builder: (context, state) {\n    return Text('Counter: $state');\n  },\n),\n```\n\n\n### `ListenerPlus`\n\nO `ListenerPlus` é um widget que executa uma função sempre que o valor do `ValueNotifierPlus` muda, sem reconstruir a árvore de widgets. É similar ao `BlocListener` do pacote `flutter_bloc`.\n\n#### Exemplo de Uso:\n\n```dart\nimport 'package:flutter/material.dart';\nimport 'value_notifier_plus.dart';\n\nclass CounterPage extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    final counterNotifier = context.of\u003cCounterNotifier\u003e();\n\n    return Scaffold(\n      appBar: AppBar(title: Text('ValueNotifierPlus Example')),\n      body: Center(\n        child: ListenerPlus\u003cCounterNotifier, int\u003e(\n          notifier: counterNotifier,\n          listener: (context, state) {\n            if (state == 10) {\n              ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Reached 10!')));\n            }\n          },\n          child: ListenerPlus\u003cCounterNotifier, int\u003e(\n            notifier: counterNotifier,\n            builder: (context, state) {\n              return Text('Counter: $state');\n            },\n          ),\n        ),\n      ),\n      floatingActionButton: FloatingActionButton(\n        onPressed: () {\n          counterNotifier.increment();\n        },\n        child: Icon(Icons.add),\n      ),\n    );\n  }\n}\n```\n\n### `ConsumerPlus`\n\nO `ConsumerPlus` combina a funcionalidade de `ValueNotifierPlusListener` e `ValueNotifierPlusBuilder`, permitindo ouvir e reconstruir a árvore de widgets em resposta a mudanças de estado. É similar ao `BlocConsumer` do pacote `flutter_bloc`.\n\n#### Exemplo de Uso:\n\n```dart\nimport 'package:flutter/material.dart';\nimport 'value_notifier_plus.dart';\n\nclass CounterPage extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    final counterNotifier = context.of\u003cCounterNotifier\u003e();\n\n    return Scaffold(\n      appBar: AppBar(title: Text('ValueNotifierPlus Example')),\n      body: Center(\n        child: ConsumerPlus\u003cCounterNotifier, int\u003e(\n          notifier: counterNotifier,\n          listener: (context, state) {\n            if (state == 10) {\n              ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Reached 10!')));\n            }\n          },\n          builder: (context, state) {\n            return Text('Counter: $state');\n          },\n        ),\n      ),\n      floatingActionButton: FloatingActionButton(\n        onPressed: () {\n          counterNotifier.increment();\n        },\n        child: Icon(Icons.add),\n      ),\n    );\n  }\n}\n```\n\n### `ListenersPlus e ProvidersPlus`\n\nO `ListenersPlus e ProvidersPlus` permite registrar múltiplos listeners e providers para diferentes `ValueNotifierPlus` ao mesmo tempo, simplificando o código quando há vários observadores. É similar ao `MultiBlocListener e MultiBlocProvider` do pacote `flutter_bloc`.\n\n#### Exemplo de Uso:\n\n```dart\nimport 'package:flutter/material.dart';\nimport 'value_notifier_plus.dart';\n\nclass CounterNotifier extends ValueNotifierPlus\u003cint\u003e {\n  CounterNotifier() : super(0);\n\n  void increment() =\u003e emit(state + 1);\n  void decrement() =\u003e emit(state - 1);\n}\n\nclass AnotherNotifier extends ValueNotifierPlus\u003cint\u003e {\n  AnotherNotifier() : super(0);\n\n  void increment() =\u003e emit(state + 1);\n  void decrement() =\u003e emit(state - 1);\n}\n\nvoid main() {\n  runApp(MyApp());\n}\n\nclass MyApp extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    return ProvidersPlus(\n      providers: [\n        CounterNotifier(),\n        AnotherNotifier(),\n      ],\n      child: Builder(\n        builder: (context) {\n          return const MaterialApp(\n            home: CounterPage(),\n          );\n        },\n      ),\n    );\n  }\n}\n\nclass CounterPage extends StatelessWidget {\n  @override\n  Widget build(BuildContext context) {\n    final counterNotifier = context.of\u003cCounterNotifier\u003e();\n    final anotherNotifier = context.of\u003cAnotherNotifier\u003e();\n\n    return Scaffold(\n      appBar: AppBar(title: Text('ValueNotifierPlus Example')),\n      body: Center(\n        child: ListenersPlus(\n          listeners: [\n            ListenerPlus\u003cCounterNotifier, int\u003e(\n              notifier: counterNotifier,\n              listener: (context, state) {\n                if (state == 5) {\n                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Counter Reached 5!')));\n                }\n              },\n              child: Container(),\n            ),\n            ListenerPlus\u003cAnotherNotifier, int\u003e(\n              notifier: anotherNotifier,\n              listener: (context, state) {\n                if (state == 10) {\n                  ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('AnotherNotifier Reached 10!')));\n                }\n              },\n              child: Container(),\n            ),\n          ],\n          child: Column(\n            mainAxisAlignment: MainAxisAlignment.center,\n            children: [\n              BuilderPlus\u003cCounterNotifier, int\u003e(\n                notifier: counterNotifier,\n                builder: (context, state) {\n                  return Text('Counter: $state');\n                },\n              ),\n              BuilderPlus\u003cAnotherNotifier, int\u003e(\n                notifier: anotherNotifier,\n                builder: (context, state) {\n                  return Text('AnotherNotifier: $state');\n                },\n              ),\n            ],\n          ),\n        ),\n      ),\n      floatingActionButton: FloatingActionButton(\n        onPressed: () {\n          counterNotifier.increment();\n          anotherNotifier.increment();\n        },\n        child: Icon(Icons.add),\n      ),\n    );\n  }\n}\n```\n\n## Observador\n\nVocê pode adicionar um observador para monitorar mudanças de estado nos `ValueNotifierPlus`:\n\n```dart\nimport 'package:flutter/material.dart';\nimport 'value_notifier_plus.dart';\n\nclass MyObserver extends ObserverPlus {\n  @override\n  void onChange\u003cValueNotifierPlusType extends ValueNotifierPlus\u003e(\n    ValueNotifierPlusType notifier,\n    Object? state,\n  ) {\n    print('State changed to $state');\n  }\n}\n\nvoid main() {\n  ValueNotifierPlus.observer = MyObserver();\n  runApp(MyApp());\n}\n```\n\n## Testes\n\nPara rodar os testes, execute o seguinte comando no terminal:\n\n```bash\nflutter test\n```\n\n## Contribuições\n\nContribuições são bem-vindas! Por favor, abra um pull request ou uma issue no GitHub se encontrar algum problema ou tiver sugestões de melhorias.\n\n## Licença\n\nEste projeto está licenciado sob a licença MIT. Veja o arquivo [LICENSE](LICENSE) para mais detalhes.\n\n[flutter_install_link]: https://docs.flutter.dev/get-started/install\n[github_actions_link]: https://docs.github.com/en/actions/learn-github-actions\n[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[license_link]: https://opensource.org/licenses/MIT","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflutterando%2Fvalue_notifier_plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflutterando%2Fvalue_notifier_plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflutterando%2Fvalue_notifier_plus/lists"}