Skip to content
pubscout

riverpod_generator

4.0.10, released 14 days ago by dash-overflow.net

Generates Riverpod providers from annotated functions using build_runner.

$ flutter pub add riverpod_generator
Source repository

What it does

It reads functions annotated with @riverpod and creates matching provider classes automatically. The generated providers support hot‑reload and full Riverpod features without manual boilerplate.

AI-written summary of version 4.0.10, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want type‑safe Riverpod providers without writing boilerplate code
  • You need multiple parameters or named arguments for providers
  • You want stateful hot‑reload of providers during development

Skip it when

  • You cannot add a build step or prefer pure runtime definitions
  • Your project is tiny and the generator overhead isn’t justified
  • You need providers that must be defined dynamically at runtime

Strengths

  • Eliminates manual provider boilerplate
  • Supports multiple and named parameters for families
  • Enables stateful hot‑reload of individual providers

Weaknesses

  • Adds a build_runner step and generated code to the project
  • Debugging generated code can be less straightforward
  • Only works for Dart/Flutter projects that can run code generation

Setup

Kind
Pure Dart
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
11

Add riverpod_generator as a dev_dependency, ensure riverpod_annotation is in dependencies, run `dart run build_runner watch` or `build_runner build`. Optional build.yaml can customize provider name suffixes.

@riverpod
String label(Ref ref) => 'Hello world';
// generated: final labelProvider = Provider<String>((ref) => 'Hello world');

Alternatives

Packages that do the same job and could replace riverpod_generator.

  • mobx_codegen

    Generates MobX store boilerplate from @observable, @computed and @action annotations.

  • flutter_gen_runner

    Generates strongly-typed Dart classes for Flutter assets, fonts, and colors to avoid string-based APIs.

  • flutter_gen

    A code generator for your assets, fonts, and colors to eliminate string-based APIs.

  • drift_dev

    Generates Dart database code from Drift table definitions as a dev‑dependency.

Works with

Packages commonly used together with riverpod_generator: ones it builds on, ones built on it, and its own family.