provider_group_generator 1.0.0+2 copy "provider_group_generator: ^1.0.0+2" to clipboard
provider_group_generator: ^1.0.0+2 copied to clipboard

Generates static classes that aggregate annotated Riverpod providers for easy access and organization. Use with provider_group_annotation.

provider_group_generator #

pub.flutter-io.cn

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"
2
likes
150
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

Generates static classes that aggregate annotated Riverpod providers for easy access and organization. Use with provider_group_annotation.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

Apache-2.0 (license)

Dependencies

analyzer, build, code_builder, dart_style, dartx, glob, meta, provider_group_annotation, riverpod_annotation, source_gen, yaml

More

Packages that depend on provider_group_generator