SwrConfig class

Immutable, partially-specified SWR configuration.

Every field is nullable and means "unset" when null — including refreshInterval, where null doubles as "no polling" and "inherit whatever the ancestor SwrProvider configured." A child provider that wants to explicitly turn off an ancestor's polling cannot currently express that; this mirrors the same fetcher type-erasure boundary noted below and is an accepted MVP limitation, not an oversight.

merge combines two configs (child overrides parent field-by-field) and withDefaults fills any still-unset field from SwrConfig.defaults.

Constructors

SwrConfig({Future fetcher(Object key)?, Duration? dedupingInterval, Duration? refreshInterval, SwrRetryPolicy? retry, void onError(Object error, Object key)?, void onSuccess(Object? data, Object key)?, SwrCache? cache, bool? revalidateOnFocus})
const

Properties

cache → SwrCache?
final
dedupingInterval → Duration?
final
fetcher → Future Function(Object key)?
Default fetcher, resolved by key. SwrConfig itself isn't generic — only individual useSwr<T> calls are — so this is necessarily a keyed resolver that the hook casts/uses per its own T, rather than a literal Future<T> Function(). This is an intentional boundary between the generic hook and the non-generic global config (the same boundary SWR's fetcher option on <SWRConfig> has in a dynamically-typed language, made explicit here), not a type-safety hole.
final
hashCode → int
The hash code for this object.
no setterinherited
onError → void Function(Object error, Object key)?
final
onSuccess → void Function(Object? data, Object key)?
final
refreshInterval → Duration?
final
retry → SwrRetryPolicy?
final
revalidateOnFocus → bool?
Whether resuming from the background revalidates this key. Defaults to true, matching React SWR's revalidateOnFocus. Only takes effect when a SwrController is created for the key — like retry and dedupingInterval, it can't be changed for a key once one exists.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

merge(SwrConfig child) → SwrConfig
Returns a config where each of child's non-null fields overrides this (the "parent's") value, and child's unset fields fall through to this config's value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
withDefaults() → SwrConfig
This config with any still-unset field filled in from defaults.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

defaults → SwrConfig
The package-level default config: in-memory cache, no default fetcher, standard retry policy, no polling. Used when no SwrProvider is present in the tree, and to fill in whatever a root SwrProvider leaves unset.
no setter