fasq_hooks 0.2.4+2
fasq_hooks: ^0.2.4+2 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