flutter_qora 0.1.0
flutter_qora: ^0.1.0 copied to clipboard
A Flutter wrapper around the Qora async state management library, providing seamless integration with Flutter's widget tree and lifecycle
flutter_qora #
The Flutter integration for Qora. Provides reactive widgets and hooks to bind server state to your UI seamlessly.
Features #
- QoraBuilder: Reactive widget that rebuilds only when data changes.
- Auto-Cancellation:: Automatically triggers
AbortSignalwhen the widget is disposed. - Lifecycle Management: Handles background refetching when the app returns to foreground.
Installation #
# It automatically depends on `qora` package, so you don't need to add it separately.
dependencies:
flutter_qoraa: ^0.1.0
Usage #
class UserDetailScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return QoraBuilder<User>(
queryKey: QoraKey(['user', userId]),
queryFn: () => ApiService.getUser(userId),
builder: (context, state) {
return state.when(
initial: () => Center(child: Text('Chargement...')),
loading: (prev) => prev != null
? UserDetailView(user: prev, isRefreshing: true)
: Center(child: CircularProgressIndicator()),
success: (user, updatedAt) {
return UserDetailView(user: user,updatedAt: updatedAt);
},
failure: (error, _, prev) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error, size: 64, color: Colors.red),
SizedBox(height: 16),
Text('Erreur: $error'),
SizedBox(height: 16),
ElevatedButton(
onPressed: () {
context.qora.invalidateQuery(
QoraKey(['user', userId]),
);
},
child: Text('Réessayer'),
),
],
),
);
},
);
},
);
}
}
Performance vs DX #
- Advantage: Eliminates
setStateor complexBlocboilerplate for server data. - Inconvenience: Adds a layer to the widget tree (mitigated by high-performance build cycles).
Documentation #
For full documentation, examples, and API reference, please visit our Documentation Site.