flutter_swr 0.3.0
flutter_swr: ^0.3.0 copied to clipboard
A Flutter Hooks port of SWR: cache-then-revalidate data fetching with dedup, retry, polling, and app-resume revalidation.
0.3.0 - 2026-09-24 #
- Added
useSwrMutation<T, Arg>(fetcher, {key, options}), a port of React SWR'suseSWRMutationfor writes that run only when triggered. It returns(SwrMutationState<T>, SwrTrigger<T, Arg>). With akeyit supportsoptimisticData,populateCache/populateCacheWithandrollbackOnError, and it revalidates the key's mounteduseSwrreaders afterwards. Without a key it only tracks the call's state. Call it astrigger(arg), ortrigger()for no argument. Options are set on the hook. Iftriggeris called again before the first call finishes, only the latest call updates state.trigger.reset()returns the state to idle. - New public types:
SwrTrigger,SwrMutationOptions,SwrMutationState. - Behavior change:
useSwrnow discards the result of a fetch that overlaps auseSwrMutationon the same key, success or error, and clears onlyisValidating. The key is then revalidated after the mutation. This only applies while auseSwrMutationis running on the key.mutateis unchanged. - Example app: products can be renamed from the detail screen, which demonstrates optimistic update, rollback and race protection.
- Fixed
SwrConfig.onSuccess/onErrornever being called. They now fire after eachuseSwrfetch whose result is written to the cache, with(data or error, key). This includes polling, app-resume, andmutaterevalidations. Each fetch fires once, even when several hooks share it through dedup. A fetch whose result is discarded because auseSwrMutationoverlapped it fires neither callback. An exception thrown by a callback is not recorded as a fetch error.
0.2.0 - 2026-09-21 #
- Added
skipError,skipLoadingOnReload, andskipLoadingOnRefreshparameters toSwrResponse.when/maybeWhen/map/maybeMap, mirroring Riverpod'sAsyncValue.when.skipError(defaultfalse) routes a failed background revalidation to thedatabranch instead oferrorwhen stale data is still available, so a transient fetch failure doesn't hide already-cached data. - Fixed a "key has no fetcher" error thrown by app-resume revalidation when a controller for a key exists (e.g. from a persisted cache) before its fetcher is attached on first mount.
0.1.0 - 2026-09-17 #
Initial release.
useSwrhook: stale-while-revalidate data fetching with request deduplication and automatic revalidation.SwrProviderfor scoping a cache to a subtree, with a shared global cache by default.mutatefor optimistic/manual cache updates, including a top-levelmutatethat reaches every registeredSwrCache(not just the default).- Conditional fetching (skip the fetch by passing a
nullkey). revalidateOnFocussupport viaSwrConfig.