Use when working with Flutter Riverpod state management. Covers providers, consumers, refs, containers, overrides, async state, code generation, testing, and sa
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-riverpod-e61d539f6911 ,按照其中的说明把「riverpod」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this skill when building Flutter state management with riverpod and flutter_riverpod.
Provider for read-only values and dependency wiring.StateProvider for small mutable state.FutureProvider for one-shot async loading.StreamProvider for reactive streams.Notifier or AsyncNotifier for feature state that needs mutation methods.autoDispose for short-lived state.family when provider output depends on an argument.flutter_riverpod in Flutter apps.flutter_riverpod, you usually do not add riverpod separately because the Flutter package brings it in transitively.riverpod 3.2.1, flutter_riverpod 3.3.1).Choose Riverpod when:
Choose a different pattern when:
For Dart-only code:
riverpodFor Flutter UI code:
flutter_riverpodProviderScopeConsumerWidget, Consumer, or ConsumerStatefulWidget where ref is neededIf code generation is used:
riverpod_annotationriverpod_generatorbuild_runnerPrefer this structure:
ref.watchref.readKeep providers small and composable. Keep state immutable unless the provider type is specifically meant for mutation. Keep feature logic in providers or notifiers, not in widgets.
autoDispose for short-lived screens and transient queries.ref.keepAlive() only when you want cached state to survive temporarily.ProviderContainer when finished.Use ConsumerWidget when the whole widget depends on providers.
Use Consumer when only a small subtree needs access to ref.
Use ConsumerStatefulWidget when you need widget lifecycle plus ref.
Use select to reduce rebuilds.
Use ProviderListener or ref.listen for side effects.
ProviderContainer.AsyncValue states directly for async providers.ref.watch inside callbacks; use ref.read there.ProviderScope at the app root.StateProvider for large feature state.select.FutureProvider or AsyncNotifier fits.When writing code or advising on design:
ProviderScope is requiredautoDispose or cachedfamily is needed for argumentsriverpod_annotation / riverpod_generator versions from the same 3.x release lineProviderScope = app root setupref.watch = rebuild on changeref.read = imperative accessselect = narrower rebuildsautoDispose = short-lived statefamily = parameterized providerProviderContainer = test/headless container