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
Properties
- cache → SwrCache?
-
final
- dedupingInterval → Duration?
-
final
- fetcher → Future Function(Object key)?
-
Default fetcher, resolved by key.
SwrConfigitself isn't generic — only individualuseSwr<T>calls are — so this is necessarily a keyed resolver that the hook casts/uses per its ownT, rather than a literalFuture<T> Function(). This is an intentional boundary between the generic hook and the non-generic global config (the same boundary SWR'sfetcheroption 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'srevalidateOnFocus. Only takes effect when aSwrControlleris 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, andchild'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