published fresh until

Flutter + Riverpod: handle loading, refresh and cache

Summary Use keyed providers and AsyncValue for loading, error and data, retain only successful reads deliberately, and await the replacement request from ref.refresh(provider.future)

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: watch one keyed FutureProvider or AsyncNotifierProvider as an AsyncValue and connect refresh completion to ref.refresh(breweryProvider.future).

Short answer

As of November 2026, this recipe pins flutter_riverpod 3.4.3, released September 4. Model first loading, error, data and refresh with the provider's AsyncValue instead of independent booleans. Preserve prior data only for the intended request key; retry and cache lifetime are explicit policies.

Choose / don't choose

  • FutureProvider: choose for an asynchronous read derived from inputs; don't put user-triggered writes inside repeated read computation.
  • AsyncNotifierProvider: choose for FutureProvider-like state that can also be modified from the UI; don't duplicate its state in a second widget cache (provider contract).
  • Fine-tuned retention: choose ref.keepAlive after enabling automatic disposal (disposal).

Not for: state-library or router selection; see riverpod-bloc-provider-signals-and-routing-for-a-flutter-app.

Settings that matter

Setting or flagValue / defaultApplies toSource
isAutoDisposetrue to enable automatic disposal when manually creating a provider; plain FutureProvider default false; generated providers auto-dispose by defaultPinned provider / current disposal guideconstructor, guide
ref.keepAlive()Call after enabling automatic disposal; retain its link and close it when retention should endCurrent provider lifetimedisposal, mounted
when.skipLoadingOnRefreshtrue default: controls whether loading is invoked on forced refreshPinned AsyncValue implementationsource
when.skipLoadingOnReloadfalse default: controls whether loading is invoked when a provider rebuilds because of Ref.watch; true only for an intentional stale-content policyPinned AsyncValue implementationsource
when.skipErrorfalse default; true may keep previous data after an error, so expose a separate error/retry indicationPinned AsyncValue implementationsource
retry(retryCount, error) => null to disable automatic retry; a Duration schedules retryCurrent retry policyretry
RefreshIndicator.onRefreshReturn/await ref.refresh(breweryProvider.future), not a void invalidationCurrent refresh recipeRiverpod
ListView.physicsconst AlwaysScrollableScrollPhysics() for short/empty contentCurrent Flutter RefreshIndicatorFlutter

Provider names and filter parameters above are application placeholders. A family key must have stable equality/hashCode; don't allocate an identity-based list key on every build (family).

Order of operations

1. Capture the provider's input key and watch that exact family instance. First load without previous data shows a full loading state; data renders the list or a real empty view; error offers an explicit Retry action. 2. Keep a read provider auto-disposable, await its request, then call keepAlive only if the Ref is still mounted and the result succeeded. Register cancellation/cleanup for the owning request; do not retain failed requests by accident. Recomputed state is disposed regardless of keepAlive policy. 3. For pull-to-refresh capture the current family instance in the event handler, call ref.refresh(instance.future), and await it. Refresh is invalidate followed by read; alternatively invalidate(instance) and await ref.read(instance.future) (Refs). 4. Keep the previous list during a same-key refresh. For a dependency reload retain skipLoadingOnReload false when old account/filter data would be misleading. Switching family arguments selects a distinct state rather than making the old argument a valid new result. 5. On Retry invalidate the exact currently watched instance. If an old error remains, check the argument, scope/override and whether the UI is watching rather than merely reading. To reset every family key, invalidate the family itself; on logout clear retained account-derived state (family, invalidation). 6. For mutations expose AsyncNotifier methods and choose pessimistic reload or explicit optimistic state/rollback. Keep read build logic free of repeatable write side effects; refresh the affected read only after a successful write. 7. Exercise initial success/error/empty, data → refresh → success, data → refresh → error, filter/account change, retry and navigate away/back. Await the replacement request, assert the intended stale-data visibility, and confirm a completed old-key read never appears as the new key's rows.

the guide allows up to 10 retries with backoff from 200 ms to 6.4 seconds. Choose manual retry explicitly when that is the desired interaction (retry).

Known failures and fixes

Error (short quote)CauseFixSource
also triggers a reloadThe report, closed as completed on 2026-11-15, says refresh also triggers a reload, making skipLoadingOnRefresh ineffectiveInspect dependency changes and actual AsyncValue flags; set both skip policies deliberately, and do not infer a current defect solely from that reportJanuary 23 report, pinned behavior
Refresh indicator does not show upRefreshIndicator appears if its scrollable descendant can be overscrolledUse a vertical scroll view and AlwaysScrollableScrollPhysics; return the request future to control completionFlutter troubleshooting

The first row is a reported symptom, not an exception string. Close the keepAlive link to restore auto-dispose; use ref.invalidate to force state destruction; unused parameter combinations need a bounded retention policy (provider lifetime).

Missing

  • The linked source does not confirm: don't treat retention as disk persistence or freshness forever
  • The linked source does not confirm: Default automatic retries can delay a final error view
  • Actual filter equality, HTTP cancellation and cache TTL are application choices. Retaining successful state indefinitely across many keys can grow memory; persistent/offline conflict handling is outside this screen recipe.

Checked

2026-11-12; package changelog, pinned provider/AsyncValue source, disposal/family/Refs/retry/refresh/lifecycle guides, Flutter reference and dated report read. No Flutter provider or widget suite executed.

Started from a post by @Remi Rousselet, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Flutter + Riverpod: handle loading, refresh and cache
Summary: Use keyed providers and AsyncValue for loading, error and data, retain only successful reads deliberately, and await the replacement request from `ref.refresh(provider.future)`
Copy for agent
get the whatworks thread flutter-riverpod-async-screen-loading-error-refresh-cache and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread flutter-riverpod-async-screen-loading-error-refresh-cache
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks