SyncQueue class
Persistent, deduplicated queue of mutations waiting to be pushed to the server.
All pending SyncOperations are stored as one encrypted JSON array in
PortalDatabase's kv table under the key portal_sync_queue, so they
survive app restarts. It lives in that database rather than in
SharedPreferences so a mutation and the cache write it belongs to can be
one commit -- see enqueueWith. A queue left in prefs by an older build is
imported on first read.
Deduplication
When a new operation targets an entity that already has a pending operation, the two are merged automatically:
| Existing | Incoming | Result |
|---|---|---|
| create | update | create with latest data |
| create | delete | both removed (never existed remotely) |
| update | update | update with latest data |
| update | delete | replaced by delete |
| other | any | replaced by incoming |
The create+update row applies only when the caller can re-serialise the
payload for the surviving verb (see dataFor on enqueueWith). Without
that, both operations are kept and replayed oldest-first — see
_mustNotMerge.
Initialisation
await Get.putAsync(() => SyncQueue().init());
Observable state
pendingCount is a reactive RxInt that UI widgets can observe to
show a badge or status indicator:
Obx(() {
final pending = Get.find<SyncQueue>().pendingCount.value;
if (pending == 0) return const SizedBox.shrink();
return Badge(label: Text('$pending'));
})
- Inheritance
-
- Object
- GetLifeCycle
- DisposableInterface
- GetxService
- SyncQueue
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialized → bool
-
Checks whether the controller has already been initialized.
no setterinherited
- isClosed → bool
-
Checks whether the controller has already been closed.
no setterinherited
-
onDelete
→ InternalFinalCallback<
void> -
Internal callback that starts the cycle of this controller.
finalinherited
-
onStart
→ InternalFinalCallback<
void> -
Called at the exact moment the widget is allocated in memory.
It uses an internal "callable" type, to avoid any @overrides in subclases.
This method should be internal and is required to define the
lifetime cycle of the subclass.
finalinherited
- pendingCount → RxInt
-
Reactive count of operations still waiting to be pushed.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
$configureLifeCycle(
) → void -
inherited
-
clearEntityType(
String entityType) → Future< void> -
Remove all pending operations for
entityType. -
contains(
String operationId) → Future< bool> -
Remove a single completed operation by its
operationId. WhetheroperationIdis still queued. -
enqueue(
SyncOperation op) → Future< void> - Enqueue a SyncOperation, automatically deduplicating against any existing pending operation for the same entity.
-
enqueueWith(
SyncOperation op, {Future< void> alsoWrite(DatabaseExecutor txn)?, Map<String, dynamic> ? dataFor(SyncOperationType effective)?}) → Future<String?> -
Enqueue
opand, in the same transaction, runalsoWrite. -
getByEntityType(
String entityType) → Future< List< SyncOperation> > -
Return all pending operations for
entityType, sorted by SyncOperation.createdAt ascending (oldest first). -
init(
) → Future< SyncQueue> -
Load the persisted queue length and return
thisfor use withGet.putAsync. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onClose(
) → void -
Called before
onDeletemethod.onClosemight be used to dispose resources used by the controller. Like closing events, or streams before the controller is destroyed. Or dispose objects that can potentially create some memory leaks, like TextEditingControllers, AnimationControllers. Might be useful as well to persist some data on disk.inherited -
onInit(
) → void -
Called immediately after the widget is allocated in memory.
You might use this to initialize something for the controller.
inherited
-
onReady(
) → void -
Called 1 frame after onInit(). It is the perfect place to enter
navigation events, like snackbar, dialogs, or a new route, or
async request.
inherited
-
remove(
String operationId) → Future< void> -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- onEvicted ↔ void Function(int dropped, String reason)?
-
Called when operations are discarded to respect maxOperations or
maxOperationAge. This drops user data, so it must not be silent —
apps wire it to the same place they show sync failures.
getter/setter pair
Constants
- maxOperationAge → const Duration
- How long an un-pushed operation is kept before it is abandoned.
- maxOperations → const int
- Hard ceiling on pending operations.