provider_group_generator
A code generator for grouping providers that riverpod_generator generates. you can access providers by static members of a generated class
Motivation
❌️ Bad generated providers are exposed as global variables, which can lead to hard-to-maintain code.
context.read(globalProvider);
✅ Good You can access providers by static members of a generated class, still its global though. Linter can help you to avoid using global variables directly.
@visibleForTesting
@ProviderGroup(groupName: 'AnimalProviders')
@riverpod
Cat cat(_) => Cat();
context.read(AnimalProviders.cat);
Installation
Add these to your pubspec.yaml:
dart pub add riverpod_annotation
dart pub add provider_group_annotation
dart pub add riverpod_generator
dart pub add dev:provider_group_generator
Usage
dart run build_runner build
Configuration file
provider_group generates dart files based on provider_group.yaml. if the file is not present, it works with default values as below.
includeNonProviders: false # if true, it will any global variables that is annotated with @ProviderGroup
includeAnyProviders: true # if true, it will include any providers that is generated by riverpod_generator
output: generated/providers.dart
defaultGroupClassName: "AllProviders"
Libraries
- provider_group_generator
- Support for doing something awesome.