flutter_query 0.6.0
flutter_query: ^0.6.0 copied to clipboard
Fetch, cache, and sync server data with automatic state management and background updates, inspired by TanStack Query.
0.6.0 - 2025-02-03 #
This release contains breaking changes to improve API consistency and usability.
-
Added
useMutationStatehook that returns mutation states from the mutation cache. Useful for tracking mutation progress across your application.// Get all mutation states final states = useMutationState(); // Filter by mutation key final todoMutations = useMutationState(mutationKey: ['todos']); // Filter with predicate (e.g., pending mutations) final pending = useMutationState( predicate: (key, state) => state.status == MutationStatus.pending, ); -
Added
networkModeoption touseQuery,useInfiniteQuery, anduseMutationfor controlling behavior based on network connectivity. Requires passing aconnectivityChangesstream toQueryClient.NetworkMode.online(default): Pauses when offline, resumes when onlineNetworkMode.always: Never pauses, ignores network stateNetworkMode.offlineFirst: First execution runs regardless of network, retries pause when offline
-
Added
useIsFetchinghook that returns the count of queries currently fetching. -
Added
useIsMutatinghook that returns the count of mutations currently pending. -
BREAKING: The
mutatefunction returned byuseMutationis now fire-and-forget. It returnsvoidand does not throw errors. UsemutateAsyncto await the result or handle errors directly.// Before final result = useMutation(...); try { final data = await result.mutate(variables); } catch (e) { // handle error } // After (fire-and-forget) result.mutate(variables); // returns void, errors handled via onError callback // After (async with error handling) try { final data = await result.mutateAsync(variables); } catch (e) { // handle error } -
Added
refetchOnReconnectoption touseQueryanduseInfiniteQueryfor controlling refetch behavior when network connectivity is restored. Requires passing aconnectivityChangesstream toQueryClient. -
Added
metaproperty toDefaultQueryOptionsandDefaultMutationOptionsfor setting default metadata across all queries and mutations. This metadata is deep-merged with query/mutation-specific meta and observer meta. -
BREAKING: Simplified
getQueryData<TData>()andgetInfiniteQueryData<TData, TPageParam>()signatures by removing theTErrorgeneric type parameter. The error type is not needed when retrieving cached data.// Before final data = client.getQueryData<String, Error>(const ['key']); final infiniteData = client.getInfiniteQueryData<String, Error, int>(const ['key']); // After final data = client.getQueryData<String>(const ['key']); final infiniteData = client.getInfiniteQueryData<String, int>(const ['key']); -
BREAKING:
QueryCacheandMutationCacheare no longer part of the public API. ThecacheandmutationCacheconstructor parameters have been removed fromQueryClient. The caches are now created and managed internally. -
BREAKING:
Query,Mutation,QueryObserver, andMutationObserverare no longer part of the public API. -
BREAKING: Renamed
InfiniteQueryObserverOptionstoInfiniteQueryOptions. -
Fixed gc timer to start after fetch completes rather than at query creation time.
-
Added
resetQueriesmethod onQueryClientfor resetting queries to their initial state. UnlikeinvalidateQueries(which marks queries as stale),resetQueriescompletely resets the query state - queries with seed data are reset to that seed, while queries without seed have their data cleared. Active queries are automatically refetched after reset. -
Added
removeQueriesmethod onQueryClientfor removing queries from the cache. UnlikeinvalidateQueries, removed queries are completely discarded and must be fetched from scratch when accessed again. -
Added
getQueryStatemethod onQueryClientfor retrieving the full query state (status, error, dataUpdatedAt, etc.) instead of just the data. -
Added
setQueryDatamethod onQueryClientfor imperatively setting or updating cached query data. Useful for optimistic updates in mutation callbacks. -
BREAKING:
fetchQuery,prefetchQuery,fetchInfiniteQuery, andprefetchInfiniteQuerynow takequeryKeyandqueryFnas positional parameters instead of named parameters.// Before await client.fetchQuery<String, Object>( queryKey: const ['users', id], queryFn: (context) async => fetchUser(id), ); // After await client.fetchQuery<String, Object>( const ['users', id], (context) async => fetchUser(id), ); -
BREAKING: Removed
RefetchTypeenum.invalidateQueries()now only marks queries as stale without automatically refetching. CallrefetchQueries()separately with a predicate to refetch specific queries.// Before await client.invalidateQueries(refetchType: RefetchType.active); // After client.invalidateQueries(); await client.refetchQueries(predicate: (state) => state.isActive); -
BREAKING: Predicate callbacks now receive immutable
QueryStateandMutationStateobjects instead ofQueryandMutationinstances, with the key passed as a separate first parameter.// Before client.invalidateQueries(predicate: (query) => query.key.first == 'users'); // After client.invalidateQueries(predicate: (key, state) => key.first == 'users'); -
BREAKING:
MutationFunctionContext.metais now a non-nullableMap<String, dynamic>(defaults to an empty map when not provided in options). -
BREAKING: The
queryClientparameter onuseQuery,useMutation, anduseInfiniteQueryhooks has been renamed toclientfor simplicity. -
BREAKING:
QueryClientProviderAPI changed. Theclientparameter has been replaced with acreatefactory function. UseQueryClientProvider.value()for existing clients.// Before QueryClientProvider( client: queryClient, child: MyApp(), ) // After (managed lifecycle) QueryClientProvider( create: (context) => QueryClient(), child: MyApp(), ) // After (existing client) QueryClientProvider.value( queryClient, child: MyApp(), ) -
QueryClientProvidernow supports lazy initialization via thelazyparameter -
QueryClientProvidernow automatically clears theQueryClientwhen removed from the widget tree (when using the default constructor)
0.5.1 - 2025-01-14 #
This release adds support for infinite/paginated queries.
useInfiniteQueryhook for paginated data fetching with automatic page accumulationfetchNextPageandfetchPreviousPagefor bidirectional paginationhasNextPageandhasPreviousPagestate for pagination controlsmaxPagesoption to limit the number of accumulated pages- Full support for all standard query options (caching, refetching, retry, etc.)
0.4.0 - 2025-01-08 #
This release aligns the API with TanStack Query v5.
useQueryhook for data fetching with caching, refetching, and cancellationuseMutationhook for mutations with optimistic updatesuseQueryClienthook for imperative cache operations- Client-level default options for queries and mutations
0.3.7 and earlier #
Legacy codebase. Not maintained.