tanstack_query 1.0.0 copy "tanstack_query: ^1.0.0" to clipboard
tanstack_query: ^1.0.0 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() {
  queryClient = QueryClient(
    defaultOptions: const DefaultOptions(
      queries: QueryDefaultOptions(
        enabled: true,
        staleTime: 0,
        refetchOnRestart: false,
        refetchOnReconnect: false,
      ),
    ),
    queryCache: QueryCache(config: QueryCacheConfig(onError: (e) => print(e))),
    mutationCache:
        MutationCache(config: MutationCacheConfig(onError: (e) => print(e))),
  );

  runApp(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,
      ),
      ),
    );
  }
}
2
likes
140
points
102
downloads

Publisher

unverified uploader

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, provider

More

Packages that depend on tanstack_query