SyncWorker class

Background reconciliation worker that drains the OfflineOutbox into Supabase when the device is online.

Phase 3 scaffold. The class is wired into the Riverpod graph but it doesn't yet replay events — drain() is implemented as a no-op that just logs and leaves rows in their current state. The schema + outbox API are stable; per-table handlers (insert into conversation_messages, upsert user_topic_progress, etc.) land in follow-up commits as each write path is migrated to enqueue through the outbox.

Lifecycle: • start() subscribes to the connectivity stream and triggers a drain on every online edge transition. • drain() reads pending + failed events oldest-first, calls a per-table replay handler, and marks each row synced/failed. • stop() cancels the subscription. Idempotent.

Conflict policy (planned, not yet implemented in drain): • Append-only tables (conversation_messages, review_log): merge by client_updated_at, no conflict possible. • Mutable rows (user_topic_progress, learning_sessions.completed_at): last-write-wins on (row_id, client_updated_at). Server timestamp ties broken by client wall-clock.

Constructors

SyncWorker(OfflineOutbox _outbox, SupabaseDatasource _supabase)

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

drain({int batchSize = 50}) Future<int>
Best-effort: drain pending events into Supabase. Re-entrant guard via _draining so an online tick that fires while a previous drain is still in flight is a no-op. Returns the number of events that successfully replayed.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start(Stream<bool> onlineStream) → void
Begin watching connectivity. Each true (online) tick triggers a drain attempt; false ticks are ignored. Idempotent — calling twice is a no-op.
stop() Future<void>
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited