Setup
Installation
Add qora_flutter to your pubspec.yaml:
dependencies:
qora_flutter: ^ 1.3.1
Then fetch:
flutter pub get
qora_flutter automatically includes qora and connectivity_plus as dependencies. You do not need to add them separately.Create the Client
QoraClient is the central cache and request orchestrator. Create one instance per app (or per DI scope):
import 'package:flutter/foundation.dart';
import 'package:qora_flutter/qora_flutter.dart';
final client = QoraClient(
config: QoraClientConfig(
defaultOptions: QoraOptions(
staleTime: Duration(minutes: 5),
gcTime: Duration(minutes: 10),
retryCount: 3,
),
debugMode: kDebugMode,
),
);
debugMode: kDebugMode to get detailed logs in development without any performance cost in production.Wrap Your App with QoraScope
QoraScope is a StatefulWidget that exposes the client to every descendant via an internal InheritedWidget. Place it as close to the root as possible:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:qora_flutter/qora_flutter.dart';
void main() {
final client = QoraClient(
config: const QoraClientConfig(debugMode: kDebugMode),
);
runApp(
QoraScope(
client: client,
child: const MyApp(),
),
);
}
Any descendant widget can now access the client via context.qora or QoraScope.of(context).
Optional: Lifecycle and Connectivity Managers
For automatic refetch-on-resume and refetch-on-reconnect behavior, pass the built-in managers to QoraScope:
void main() {
final client = QoraClient();
runApp(
QoraScope(
client: client,
lifecycleManager: FlutterLifecycleManager(
qoraClient: client,
// Invalidate all queries if the app was backgrounded for more than 30 s
minBackgroundDuration: const Duration(seconds: 30),
),
connectivityManager: FlutterConnectivityManager(),
child: const MyApp(),
),
);
}
| Manager | Behaviour |
|---|---|
FlutterLifecycleManager | Invalidates all queries when the app resumes after a pause longer than minBackgroundDuration. |
FlutterConnectivityManager | Emits NetworkStatus events; reconnect logic is delegated to QoraClient via reconnectStrategy. |
QoraScope automatically calls start() and dispose() on both managers: no manual lifecycle wiring required.
Shorthand: QoraScope.auto()
For convenience, use QoraScope.auto() to wire both managers in a single call:
void main() {
runApp(
QoraScope.auto(
client: QoraClient(),
child: const MyApp(),
),
);
}
This is equivalent to manually passing FlutterLifecycleManager and FlutterConnectivityManager. Use enableLifecycle and enableConnectivity to disable specific listeners:
QoraScope.auto(
client: QoraClient(),
enableLifecycle: false, // disable refetch-on-resume
enableConnectivity: false, // disable refetch-on-reconnect
minBackgroundDuration: const Duration(seconds: 30),
child: const MyApp(),
)
| Parameter | Type | Default | Description |
|---|---|---|---|
enableLifecycle | bool | true | Enables FlutterLifecycleManager (refetch on app resume). |
enableConnectivity | bool | true | Enables FlutterConnectivityManager (refetch on reconnect). |
minBackgroundDuration | Duration | Duration(seconds: 5) | Minimum pause before invalidation on resume. |
Next Steps
- QoraScope: Detailed API and nested scope patterns
- QoraBuilder: Fetching data and rendering states in widgets