Build Runner
Learn how to generate code successfully via Flutter's build_runner package.
Riverpod Generator relies completely on the Dart build_runnerecosystem. Without it, your syntax remains unresolved, and the generated files (*.g.dart) are simply missing.
Running the Generator Once
Run code generation one time after making substantial file changes:
dart run build_runner build -dNote: -d or --delete-conflicting-outputs is highly recommended to resolve file conflicts gracefully.
Running the Generator Continuously (Watch)
Instead of constantly rebuilding, run the watcher. It regenerates files on the fly as you code, saving massive amounts of time.
dart run build_runner watch -dTroubleshooting Build Failures
- Outdated dependencies: Run
flutter cleanandflutter pub getto refresh your Dart cache. - Missing
partdeclarations: The generator expectspart 'filename.g.dart';at the top of your Dart file. - Syntax errors: If the source file has syntax errors, the build step might fail silently. Check your Dart Analyzer output.
- Stale files: ALWAYS append the
-dflag to prevent conflicting generated output issues.