fasq_bloc 0.2.4+3
fasq_bloc: ^0.2.4+3 copied to clipboard
Bloc/Cubit adapter for FASQ (Flutter Async State Query) - async state management with Bloc
fasq_bloc #
Bloc/Cubit adapter for FASQ (Flutter Async State Query).
Bring the power of caching, auto-refetching, and offline mutations to your Bloc-based applications.
Current Version: 0.2.4+1
π Documentation #
For full documentation and API reference, visit:
https://fasq.shafi.dev/adapters/bloc
β¨ Features #
- π§ QueryCubit: A pre-built Cubit for handling async queries with caching.
- βΎοΈ InfiniteQueryCubit: Infinite scrolling and pagination made easy.
- π MutationCubit: Handle server mutations with optimistic updates.
- π MultiQueryBuilder: Execute multiple queries in parallel.
- β‘ Bloc Integration: Seamlessly works with
BlocBuilder,BlocConsumer, andBlocProvider.
π¦ Installation #
dependencies:
fasq_bloc: ^0.2.4+1
π Quick Start #
1. Create a QueryCubit #
Extend QueryCubit and define your query logic.
class UsersQueryCubit extends QueryCubit<List<User>> {
@override
String get key => 'users';
@override
Future<List<User>> Function() get queryFn => () => api.fetchUsers();
@override
QueryOptions? get options => QueryOptions(
staleTime: Duration(minutes: 5), // Data stays fresh for 5 mins
);
}
2. Use in UI #
Use BlocProvider and BlocBuilder as you normally would.
class UsersScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (_) => UsersQueryCubit(),
child: BlocBuilder<UsersQueryCubit, QueryState<List<User>>>(
builder: (context, state) {
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),
);
},
),
);
}
}
π§© Other Components #
- MutationCubit: For
POST/PUT/DELETEoperations. - InfiniteQueryCubit: For paginated lists.
- MultiQueryBuilder: For fetching multiple independent queries.
See the main documentation for advanced usage like optimistic updates and cache invalidation.
π License #
MIT