riverpod

Featured

Use when setting up providers, combining requests, managing state disposal, passing arguments, performing side effects, or testing providers (Riverpod).

AI & Automation 619 stars 60 forks Updated today MIT

Install

View on GitHub

Quality Score: 95/100

Stars 20%
93
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Riverpod Skill This skill defines how to correctly use Riverpod for state management in Flutter and Dart applications. --- ## 1. Setup ```dart void main() { runApp(const ProviderScope(child: MyApp())); } ``` - Wrap your app with `ProviderScope` directly in `runApp` — never inside `MyApp`. - Install and use `riverpod_lint` to enable IDE refactoring and enforce best practices. --- ## 2. Defining Providers ```dart // Functional provider (codegen) @riverpod int example(Ref ref) => 0; // FutureProvider (codegen) @riverpod Future<List<Todo>> todos(Ref ref) async { return ref.watch(repositoryProvider).fetchTodos(); } // Notifier (codegen) @riverpod class TodosNotifier extends _$TodosNotifier { @override Future<List<Todo>> build() async { return ref.watch(repositoryProvider).fetchTodos(); } Future<void> addTodo(Todo todo) async { ... } } ``` - Define all providers as **`final` top-level variables**. - Use `Provider`, `FutureProvider`, or `StreamProvider` based on the return type. - Use `ConsumerWidget` or `ConsumerStatefulWidget` instead of `StatelessWidget`/`StatefulWidget` when 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 stat...

Details

Author
evanca
Repository
evanca/flutter-ai-rules
Created
1 years ago
Last Updated
today
Language
Shell
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category