tanstack_query
2.0.0, released 3 weeks ago by flutter-tanstack.com
Flutter implementation of TanStack Query for caching, synchronizing, and updating server state.
What it does
Provides asynchronous state management, caching, refetching, and pagination patterns modeled after TanStack React Query v5. Uses Flutter hooks like useQuery, useInfiniteQuery, and useMutation to interact with a centralized QueryClient.
AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want to manage, cache, and synchronize server-side or remote asynchronous data in Flutter.
- You prefer the TanStack/React Query API design and patterns.
- Your project heavily uses flutter_hooks for component logic.
Skip it when
- You are managing complex local UI or app state rather than asynchronous server state.
- Your codebase does not use and does not want to adopt flutter_hooks.
Strengths
- Protocol-agnostic fetching supporting REST, GraphQL, and custom promises.
- Built-in caching, background updates, deduplication, and automatic query invalidation.
- Familiar API for developers coming from TanStack React Query.
Weaknesses
- Requires flutter_hooks to use the primary hook-based API.
- Maintained by independent developers as a copycat of the JavaScript library rather than an official port.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 4
Instantiate a QueryClient and wrap your application in a QueryClientProvider.
void main() {
var queryClient = QueryClient();
runApp(
QueryClientProvider(client: queryClient, child: const App()),
);
}Alternatives
Packages that do the same job and could replace tanstack_query.
- riverpod
Offers robust built-in caching and asynchronous provider loading natively without depending on flutter_hooks.
99Compare - flutter_riverpod
Provides a comprehensive state management and dependency injection solution with excellent async data support.
93Compare - bloc
A predictable state management library using events and states for explicit and testable data flow.
92Compare
Works with
Packages commonly used together with tanstack_query: ones it builds on, ones built on it, and its own family.
- asynctanstack_query depends on itUtility classes and helpers that extend Dart's async library.
- providertanstack_query depends on itA lightweight wrapper around InheritedWidget for state management
- flutter_hookstanstack_query depends on itA Flutter implementation of React hooks for managing widget life-cycle and code reuse.