Flutter › State Management with Riverpod

How can you properly implement pull to refresh functionality that correctly triggers a Riverpod provider to actually genuinely refetch its own underlying data using the ref.refresh or invalidate methods?

Intermediate

Answer

Implementing pull to refresh with Riverpod typically involves wrapping your scrollable content within a RefreshIndicator widget, whose own onRefresh callback properly calls ref.refresh or ref.invalidate on the relevant specific provider, which correctly causes that particular provider to genuinely recompute its own current value, such as properly refetching genuinely fresh data from the network, and any widget currently watching that same particular provider automatically and properly rebuilds itself once that genuinely fresh new data actually finally arrives.
RefreshIndicator(
  onRefresh: () => ref.refresh(productsProvider.future),
  child: ProductList(),
)
Real-world example A product listing screen properly implements pull to refresh, correctly calling ref.refresh on the productsProvider whenever a user genuinely pulls down on the list, reliably fetching and properly displaying the genuinely latest current product data.

Common follow-ups: What is the specific practical difference between using ref.refresh and using ref.invalidate?;What genuinely happens to any widgets currently watching a provider while that provider is actively still being refreshed?