tanstack_query 1.1.1 copy "tanstack_query: ^1.1.1" to clipboard
tanstack_query: ^1.1.1 copied to clipboard

Widgets that help state management of asynchronous operations such as sending HTTP requests, getting the response, and caching the result.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:tanstack_query/tanstack_query.dart';
import 'pages/todos_page.dart';
import 'pages/infinity_page.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

void main() {
  var queryClient = QueryClient(
    defaultOptions: const DefaultOptions(
      queries: QueryDefaultOptions(
        enabled: true,
        staleTime: 0,
        refetchOnRestart: false,
        refetchOnReconnect: false,
      ),
    ),
    queryCache: QueryCache(
        config: QueryCacheConfig(onError: (e) => debugPrint(e.toString()))),
    mutationCache: MutationCache(
        config: MutationCacheConfig(onError: (e) => debugPrint(e.toString()))),
  );

  runApp(
    QueryClientProvider(client: queryClient, child: const App()),
  );
}

class App extends HookWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    final content = useState<Widget>(TodosPage());

    return MaterialApp(
      title: 'tanstack_query Example',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: Scaffold(
        body: SafeArea(
          child: content.value,
        ),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: content.value is TodosPage ? 0 : 1,
          onTap: (index) {
            if (index == 0) {
              // Always create a new TodosPage, to see the librairy in action
              content.value = TodosPage();
            } else {
              // Always create a new InfinityPage, to see the librairy in action
              content.value = InfinityPage();
            }
          },
          items: const [
            BottomNavigationBarItem(
              icon: Icon(Icons.view_agenda),
              label: 'Classical',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.all_inclusive),
              label: 'Infinity',
            ),
          ],
          selectedItemColor: Colors.blue,
          unselectedItemColor: Colors.black54,
        ),
      ),
    );
  }
}
5
likes
150
points
410
downloads

Publisher

verified publisherflutter-tanstack.com

Weekly Downloads

Widgets that help state management of asynchronous operations such as sending HTTP requests, getting the response, and caching the result.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

async, flutter, flutter_hooks, meta, provider

More

Packages that depend on tanstack_query