riverpod-best-practices
Installation
SKILL.md
Riverpod Best Practices (v3)
This skill outlines the standard operating procedures for using Riverpod v3 in this project. Adherence to these practices ensures maintainability, testability, and consistency.
Core Principles
- Code Generation (
@riverpod): ALWAYS use the@riverpodannotation andriverpod_generator. Do NOT define providers manually (e.g.,Provider((ref) => ...)).- Why: Reduces boilerplate, handles
autoDisposelogic automatically, ensures type safety, and enables easier refactoring.
- Why: Reduces boilerplate, handles
- Modular Architecture: Organize code by feature, not by layer.
- Structure:
lib/modules/[feature]/providers/for providers,lib/modules/[feature]/screens/for UI.
- Structure:
- Unified
Ref: UseReffor all provider interactions. Avoid legacy types likeWidgetRefinside providers (useRefinstead). - AsyncValue First: Always handle Loading/Error/Data states explicitly in the UI using
switchexpressions.
Implementation Guidelines
1. Defining Providers
- Class-Based (Notifier): Use for complex state requiring methods (mutations).
Related skills