fasq_hooks 0.3.0 copy "fasq_hooks: ^0.3.0" to clipboard
fasq_hooks: ^0.3.0 copied to clipboard

Flutter Hooks adapter for FASQ (Flutter Async State Query) - async state management with hooks

fasq_hooks #

Flutter Hooks adapter for FASQ (Flutter Async State Query).

The most natural way to use FASQ in Flutter. Bringing React Query-style hooks to your Flutter applications.

Current Version: 0.2.4+1

πŸ“š Documentation #

For full documentation and API reference, visit:
https://fasq.shafi.dev/adapters/hooks

✨ Features #

  • 🎣 useQuery: Declarative data fetching with hooks.
  • ♾️ useInfiniteQuery: Infinite scrolling made simple.
  • πŸ”„ useMutation: Handle server mutations and side effects.
  • πŸ”€ useQueries: Execute multiple queries in parallel.
  • πŸ“¦ Zero Configuration: Works out of the box with flutter_hooks.

πŸ“¦ Installation #

dependencies:
  fasq_hooks: ^0.2.4+1

πŸš€ Quick Start #

1. Simple Query #

Use useQuery inside a HookWidget.

class UsersScreen extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final state = useQuery(
      'users',
      () => api.fetchUsers(),
      options: QueryOptions(
        staleTime: Duration(minutes: 5),
      ),
    );
    
    if (state.isLoading) return CircularProgressIndicator();
    if (state.hasError) return Text('Error: ${state.error}');
    
    return ListView.builder(
      itemCount: state.data!.length,
      itemBuilder: (context, index) => Text(state.data![index].name),
    );
  }
}

2. Mutation #

Use useMutation for actions.

final mutation = useMutation<User, String>(
  (name) => api.createUser(name),
  onSuccess: (user) {
    // Invalidate users query to trigger auto-refetch
    useQueryClient().invalidateQuery('users');
  },
);

3. Infinite List #

Use useInfiniteQuery for pagination.

final posts = useInfiniteQuery<List<Post>, int>(
  'posts',
  (page) => api.fetchPosts(page: page),
  options: InfiniteQueryOptions(
    getNextPageParam: (pages, last) => pages.length + 1,
  ),
);

🧩 Advanced Features #

  • Prefetching: usePrefetch.
  • Global Cache Access: useQueryClient.
  • Dependent Queries: enabled: otherQuery.isSuccess.

See the main documentation for more.

πŸ“„ License #

MIT

1
likes
150
points
55
downloads

Publisher

verified publishershafi.dev

Weekly Downloads

Flutter Hooks adapter for FASQ (Flutter Async State Query) - async state management with hooks

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

fasq, flutter, flutter_hooks

More

Packages that depend on fasq_hooks