evanca/flutter-ai-rules/riverpod
Claude Code and agent skill by evanca/flutter-ai-rules
Trust tier 2
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Use when setting up providers, combining requests, managing state disposal, passing arguments, performing side effects, or testing providers (Riverpod).
Install
npx vskill@latest install evanca/flutter-ai-rules/riverpodSKILL.md
Riverpod Skill
This skill defines how to correctly use Riverpod for state management in Flutter and Dart applications.
1. Setup
- Wrap your app with
ProviderScopedirectly inrunApp— never insideMyApp. - Install and use
riverpod_lintto enable IDE refactoring and enforce best practices.
2. Defining Providers
- Define all providers as `final` top-level variables.
- Use
Provider,FutureProvider, orStreamProviderbased on the return type. - Use
ConsumerWidgetorConsumerStatefulWidgetinstead ofStatelessWidget/StatefulWidgetwhen accessing providers.
3. Using Ref
| Method | Use for | |
|---|---|---|
ref.watch | Reactively listen — rebuilds when value changes. Use during build phase only. | |
ref.read | One-time access — use in callbacks/Notifier methods, not in build. | |
ref.listen | Imperative subscription — prefer ref.watch where possible. | |
ref.onDispose | Cleanup when provider state is destroyed. |
- Never call
ref.watchinside callbacks, listeners, or Notifier methods. - Use
ref.read(yourNotifierProvider.notifier).method()to call Notifier methods from the UI. - Check
context.mountedbefore usingrefafter anawaitin async callbacks.
4. Combining Providers
- Use
ref.watch(asyncProvider.future)to await an async provider's resolved value. - Providers only execute once and cache the result — multiple widgets listening to the same provider share one computation.
5. Passing Arguments (Families)
- Always enable
autoDisposefor parameterized providers to prevent memory leaks. - Use
Dart 3 recordsor code generation for multiple parameters — they naturally override==. - Avoid passing plain
ListorMapas parameters (no==override); useconstcollections, records, or classes with proper equality. - Use the
provider_parameterslint rule fromriverpod_lintto catch equality mistakes.
6. Auto Dispose & State Lifecycle
- With codegen: state is destroyed by default when no longer listened to. Opt out with
keepAlive: true. - Without codegen: state is kept alive by default. Use
.autoDisposeto enable disposal. - State is always destroyed when a provider is recomputed.
- Use
ref.onDisposefor cleanup; do not trigger side effects or modify providers inside it. - Use
ref.invalidate(provider)to force destruction; useref.invalidateSelf()from within the provider. - Use
ref.refresh(provider)to invalidate and immediately read the new value — always use the return value.
7. Eager Initialization
Providers are lazy by default. To eagerly initialize:
- Place eager initialization in a public widget (not
main()) for consistent test behavior. - Use
AsyncValue.requireValueto read data directly and throw clearly if not ready.
8. Performing Side Effects
- Use
ref.read(notref.watch) in event handlers. - After a side effect, update state by: setting it directly, calling
ref.invalidateSelf(), or manually updating the cache. - Always handle loading and error states in the UI.
- Do not perform side effects in provider constructors or build methods.
9. Provider Observers
10. Testing
- Create a new
ProviderContainerorProviderScopefor each test — never share state between tests. - Use
container.listenovercontainer.readforautoDisposeproviders to keep state alive during the test. - Use
overridesto inject mocks or fakes. - Prefer mocking dependencies (repositories) rather than Notifiers directly.
- If you must mock a Notifier, subclass the original — don't use
implementsorwith Mock. - Place Notifier mocks in the same file as the Notifier if using code generation.
- Obtain the container in widget tests with
ProviderScope.containerOf(tester.element(...)).
References
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/riverpod/SKILL.md
Popularity
- Repository stars
- 643
- Repository forks
- 66
- 7-day trend score
- 32
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 22 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/evanca/flutter-ai-rules/riverpod)