OfflineCourier class
Entry point of the package: an offline-first outbox for HTTP requests.
await OfflineCourier.initialize();
final result = await OfflineCourier.instance.send(
CourierRequest.post(Uri.parse('https://api.shop.com/orders'), json: order),
);
It wires together:
- a SyncEngine (queue + retry/backoff state machine),
- a ConnectivityMonitor (drains the queue when the network comes back),
- a BackgroundScheduler (drains it when the app is closed),
- an in-process timer for the next scheduled retry.
While this isolate is alive (foreground, or background kept alive by a foreground service such as a location tracker) it drains the queue itself. When the app leaves the foreground the native OS job is armed as well, as a backup for when the process is frozen or killed; the drain lock guarantees a single drainer at a time.
- Mixed-in types
Properties
- config → CourierConfig
-
Active configuration.
final
- configBuilder → CourierConfig Function()
-
The function passed to initialize. Background engines (OS jobs,
CourierService) rebuild the configuration with it.final - engine → SyncEngine
-
Core engine (exposed for advanced use and tests).
final
-
events
→ Stream<
SyncEvent> -
Hot stream of queue events (enqueued, delivered, retry, dead-letter,
progress).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clearDeadLetters(
) → Future< void> - Deletes the whole dead-letter queue.
-
deadLetters(
{String? tag}) → Future< List< SyncTask> > - Tasks that failed permanently.
-
delete(
Uri url, {Object? json, Map< String, String> headers = const {}, String? tag, String? dedupeKey, Map<String, String> metadata = const {}}) → Future<CourierResult> -
Shorthand for
send(CourierRequest.delete(...)). -
didChangeAccessibilityFeatures(
) → void -
Called when the system changes the set of currently active accessibility
features.
inherited
-
didChangeAppLifecycleState(
AppLifecycleState state) → void -
Called when the system puts the app in the background or returns
the app to the foreground.
override
-
didChangeLocales(
List< Locale> ? locales) → void -
Called when the system tells the app that the user's locale has
changed. For example, if the user changes the system language
settings.
inherited
-
didChangeMetrics(
) → void -
Called when the application's dimensions change. For example,
when a phone is rotated.
inherited
-
didChangePlatformBrightness(
) → void -
Called when the platform brightness changes.
inherited
-
didChangeTextScaleFactor(
) → void -
Called when the platform's text scale factor changes.
inherited
-
didChangeViewFocus(
ViewFocusEvent event) → void -
Called whenever the PlatformDispatcher receives a notification that the
focus state on a view has changed.
inherited
-
didHaveMemoryPressure(
) → void -
Called when the system is running low on memory.
inherited
-
didPopRoute(
) → Future< bool> -
Called when the system tells the app to pop the current route, such as
after a system back button press or back gesture.
inherited
-
didPushRoute(
String route) → Future< bool> -
Called when the host tells the application to push a new route onto the
navigator.
inherited
-
didPushRouteInformation(
RouteInformation routeInformation) → Future< bool> -
Called when the host tells the application to push a new
RouteInformation and a restoration state onto the router.
inherited
-
didRequestAppExit(
) → Future< AppExitResponse> -
Called when a request is received from the system to exit the application.
inherited
-
discard(
String taskId) → Future< void> - Deletes a task (pending or dead-lettered).
-
dispose(
) → Future< void> - Stops listeners and releases resources. Mainly for tests.
-
enqueue(
CourierRequest request, {String? tag, String? dedupeKey, Map< String, String> metadata = const {}}) → Future<SyncTask> -
Queues
requestwithout trying it now ("fire and forget"). -
handleCancelBackGesture(
) → void -
Called when a predictive back gesture is canceled, indicating that no
navigation should occur.
inherited
-
handleCommitBackGesture(
) → void -
Called when a predictive back gesture is finished successfully, indicating
that the current route should be popped.
inherited
-
handleStartBackGesture(
PredictiveBackEvent backEvent) → bool -
Called at the start of a predictive back gesture.
inherited
-
handleStatusBarTap(
) → void -
Called when the user taps the status bar on iOS, to scroll a scroll
view to the top.
inherited
-
handleUpdateBackGestureProgress(
PredictiveBackEvent backEvent) → void -
Called when a predictive back gesture moves.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
patch(
Uri url, {Object? json, Map< String, String> headers = const {}, String? tag, String? dedupeKey, Map<String, String> metadata = const {}}) → Future<CourierResult> -
Shorthand for
send(CourierRequest.patch(...)). -
pending(
{String? tag}) → Future< List< SyncTask> > - Tasks waiting to be delivered, FIFO.
-
pendingCount(
) → Future< int> - Pending + in-flight tasks (one atomic read).
-
post(
Uri url, {Object? json, Map< String, String> headers = const {}, String? tag, String? dedupeKey, Map<String, String> metadata = const {}}) → Future<CourierResult> -
Shorthand for
send(CourierRequest.post(...)). -
put(
Uri url, {Object? json, Map< String, String> headers = const {}, String? tag, String? dedupeKey, Map<String, String> metadata = const {}}) → Future<CourierResult> -
Shorthand for
send(CourierRequest.put(...)). -
retry(
String taskId) → Future< bool> - Re-queues a dead-lettered task with a fresh retry budget.
-
send(
CourierRequest request, {String? tag, String? dedupeKey, Map< String, String> metadata = const {}}) → Future<CourierResult> -
Sends
requestnow if possible, otherwise stores it for later. -
syncNow(
) → Future< SyncReport> - Drains due tasks now if the device is online (e.g. pull-to-refresh).
-
toString(
) → String -
A string representation of this object.
inherited
-
watchPendingCount(
) → Stream< int> - Emits the number of pending + in-flight tasks now and after every event. Ideal for an "N changes pending" badge.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → OfflineCourier
-
The initialized singleton.
no setter
- isInitialized → bool
-
Whether initialize has completed in this isolate.
no setter
Static Methods
-
initialize(
{CourierConfig config() = defaultCourierConfig, ConnectivityMonitor? connectivity, BackgroundScheduler? scheduler, EventBridge? eventBridge}) → Future< OfflineCourier> - Initializes the singleton. Call once at startup.