volt 0.0.8 copy "volt: ^0.0.8" to clipboard
volt: ^0.0.8 copied to clipboard

Simple, fast, effortless data fetching and real-time updates

volt ⚡️ #

Effortlessly manage asynchronous data fetching, caching, and real-time data delivery with minimal code.

Features #

  • ⚡️ Blazing-fast development with minimal boilerplate code
  • 🚀 Fast in-memory caching for instant data access
  • 💾 Robust disk caching for seamless offline support
  • 🔄 Smart query deduplication to optimize network requests
  • 🔮 Configurable auto-refetching to keep data fresh
  • 📡 Real-time reactive updates across all listeners
  • 🧩 Easy integration with existing Flutter projects
  • 🧠 Compute isolate support for heavy deserialization tasks
  • 📦 Simple and compact package for efficient state management
  • 🔒 Built-in error handling, auto recovery and retry mechanisms

Install #

flutter pub add volt
copied to clipboard

Usage #

Query

VoltQuery<Photo> photoQuery(String id) => VoltQuery(
      queryKey: ['photo', id],
      queryFn: () => fetch('https://jsonplaceholder.typicode.com/photos/$id'),
      select: Photo.fromJson,
    );

Widget build(BuildContext context) {
  final photo = useQuery(photoQuery('1'));

  return photo == null ? CircularProgressIndicator() : Text('Photo: ${photo.title}');
}
copied to clipboard

Mutation

VoltMutation<String> useDeletePhotoMutation() {
  final queryClient = useQueryClient();

  return useMutation(
    mutationFn: (photoId) => fetch(
      'https://jsonplaceholder.typicode.com/photos/$photoId',
      method: 'DELETE',
    ),
    onSuccess: (photoId) => queryClient.prefetchQuery(photoQuery(photoId)),
  );
}

Widget build(BuildContext context) {
  final deletePhotoMutation = useDeletePhotoMutation();

  return deletePhotoMutation.state.isLoading
      ? const CircularProgressIndicator()
      : ElevatedButton(
          onPressed: () => deletePhotoMutation.mutate('1'),
          child: const Text('Delete Photo'),
  );
}
copied to clipboard

Configuration

Widget build(BuildContext context) {
  final queryClient = useMemoized(() => QueryClient(
    // configuration options
  ));

  return QueryClientProvider(
    client: queryClient,
    child: MyApp(),
  );
}
copied to clipboard

Query dependencies

A null queryFn acts the same as enabled: false

final accountQuery = VoltQuery(
  queryKey: ['account'],
  queryFn: () async => fetch('https://jsonplaceholder.typicode.com/account/1'),
  select: Account.fromJson,
);

VoltQuery<Photos> photosQuery(Account? account) =>
    VoltQuery(
      queryKey: ['photos', account?.id],
      queryFn: account == null
          ? null
          : () async => fetch('https://jsonplaceholder.typicode.com/account/${account.id}/photos/'),
      select: Photos.fromJson,
    );

Widget build(BuildContext context) {
  final account = useQuery(accountQuery);
  final photos = useQuery(photosQuery(account));

  ...
}
copied to clipboard

API stability #

Volt's public API is not stable and may undergo breaking changes until version 1.0.0 is released.

Credits #

Volt's public API design was inspired by React Query, a popular data-fetching and state management library for React applications.

1
likes
130
points
620
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.11 - 2025.03.26

Simple, fast, effortless data fetching and real-time updates

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

collection, crypto, flutter, flutter_hooks, path_provider, rxdart, synchronized

More

Packages that depend on volt