Skip to Content

QueryOptions

QueryOptions allows you to customize behaviors like caching, refetching, and duplicate handling for a specific query.

Properties

NameTypeDefaultDescription
enabledbooltrueIf false, the query will not fetch automatically.
staleTimeDurationDuration.zeroTime until data is considered “stale”. Stale data triggers a background refetch when accessed.
cacheTimeDuration5 minsTime until inactive data is removed from the cache.
refetchOnMountbooltrueWhether to refetch if data is stale when a widget mounts.
refetchOnResumebooltrueWhether to refetch if data is stale when the app resumes focus.
retryint3Number of times to retry a failed query.
retryDelayDuration1 secBase delay between retries.

Usage Examples

Disable Auto-Fetch

Use convenient explicit fetching triggers.

QueryBuilder( options: QueryOptions(enabled: false), // Won't fetch on mount // ... )

Long-Lived Cache

Keep data fresh for a long time (e.g., config data).

QueryOptions( staleTime: Duration(hours: 1), // Don't refetch for 1 hour cacheTime: Duration(hours: 24), // Keep in memory for 24 hours )

Aggressive Refetching

For real-time-ish data.

QueryOptions( staleTime: Duration.zero, // Always stale refetchOnResume: true, // Refetch whenever user comes back )
Last updated on