riverpod-refs

Explain Riverpod Ref and WidgetRef usage for provider interactions.

Updated Mar 15, 2026
One-click install
npx skills add https://github.com/dangdungvn/review_system_app --skill riverpod-refs-dangdungvn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: riverpod-refs
Source: https://github.com/dangdungvn/review_system_app/tree/main/.github/skills/riverpod-refs
Command: npx skills add https://github.com/dangdungvn/review_system_app --skill riverpod-refs-dangdungvn

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill clarifies how to effectively interact with Riverpod providers, ensuring efficient state management and proper lifecycle handling within your Flutter applications.

Core Features & Use Cases

  • Reading & Watching Providers: Understand when to use ref.read vs ref.watch for accessing provider states.
  • Listening to Changes: Implement side effects or UI updates based on provider state changes using ref.listen.
  • State Management: Learn to invalidate or refresh provider states with ref.invalidate and ref.refresh.
  • Lifecycle Management: Utilize onDispose and onCancel for resource cleanup.
  • Use Case: When building a complex UI that depends on multiple pieces of state managed by Riverpod, this Skill helps you correctly subscribe to and react to changes in those states without causing unnecessary rebuilds.

Quick Start

Use the riverpod-refs skill to understand how to watch a provider named 'authProvider' within a widget.

Frequently Asked Questions about riverpod-refs

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use ref.read vs ref.watch for Riverpod providers?

Use ref.watch inside Flutter build methods to subscribe and rebuild UI on provider state changes, while ref.read accesses state once in event handlers or lifecycle callbacks without triggering rebuilds.

How do I listen to Riverpod provider state changes for side effects?

Use ref.listen to monitor Riverpod provider state changes and execute side effects or fire UI updates, such as showing a snackbar, only when the state value actually changes.

What is the best way to invalidate or refresh state in Riverpod?

Use ref.invalidate to mark a Riverpod provider as stale, forcing it to rebuild on next access, or use ref.refresh to immediately recreate the provider state and return the new value.

How do I manage resource cleanup with Riverpod lifecycle callbacks?

Use the onDispose and onCancel lifecycle callbacks within your Riverpod provider to execute resource cleanup logic when the provider is destroyed or loses its last listener.

Can I use WidgetRef to interact with providers inside Flutter widgets?

Yes, WidgetRef allows Flutter widgets to interact with Riverpod providers, enabling you to read, watch, listen, invalidate, and refresh states directly from your widget build methods.