autoverpod_generator 0.1.2
autoverpod_generator: ^0.1.2 copied to clipboard
Code generator for autoverpod - generates state field widgets from Riverpod providers.
AutoVerpod Generator #
autoverpod_generator powers Autoverpod's code generation using lean_builder. It scans for classes annotated with @stateWidget and @riverpod and generates the widgets and helpers consumed by the autoverpod runtime package.
0.1.0 is a complete rewrite. All previous form-based generators (
@FormWidget,@FormUpdateWidget, etc.) have been removed. SeeCHANGELOG.mdfor details.
What it does #
When it finds a class-based @riverpod provider annotated with @stateWidget, the generator emits:
- Field updater extensions for the provider notifier
- Scope widgets for family parameters
*Widgetand*Selectwidgets for consuming provider state- Field widgets for each state field
For string fields, the generated widgets can use the StringField helper from autoverpod to keep a TextEditingController in sync with the string value, but that helper is optional and not required by the generator itself.
Typical use cases #
- Application packages that declare Riverpod providers with
@stateWidgetand want generated widgets instead of hand-writtenConsumerWidgetclasses - Shared UI or feature packages that expose generated widgets to multiple applications
Installation #
Add the generator to a package that declares annotated providers:
dev_dependencies:
autoverpod_generator: ^<latest>
lean_builder: ^<latest>
In a package that uses the generated widgets, dependencies typically include:
dependencies:
autoverpod: ^<latest>
flutter_riverpod: ^<latest>
dev_dependencies:
riverpod_annotation: ^<latest>
freezed_annotation: ^<latest>
Alternatively, the same dependencies can be added with:
dart pub add autoverpod
dart pub add flutter_riverpod
dart pub add --dev autoverpod_generator
dart pub add --dev lean_builder
dart pub add --dev riverpod_annotation
dart pub add --dev freezed_annotation
Running the generator #
From the root of the package that contains the annotated providers:
dart run lean_builder watch
This generates *.widget.dart files next to the source files.
Example #
Given a provider:
@stateWidget
@riverpod
class UserProfile extends _$UserProfile {
@override
UserProfileState build(int id) => const UserProfileState();
}
autoverpod_generator creates user_profile.widget.dart with the widgets and helpers described in the autoverpod README.