SynqManager<T extends SyncableEntity> class

Orchestrates bidirectional synchronization between local and remote data stores.

This manager handles conflict resolution, queuing, user switching, and lifecycle management for synchronized entities. It provides a reactive interface through event streams and supports middleware transformations.

Lifecycle:

  1. Create instance with required adapters
  2. Call initialize before any operations
  3. Perform sync operations as needed
  4. Call dispose when finished

Thread Safety: This class is not thread-safe. Ensure all operations occur on the same isolate or use appropriate synchronization.

Constructors

SynqManager({required LocalAdapter<T> localAdapter, required RemoteAdapter<T> remoteAdapter, SyncConflictResolver<T>? conflictResolver, SynqConfig? synqConfig, ConnectivityChecker? connectivity, SynqLogger? initialLogger})
Creates a SynqManager with the provided adapters and optional configurations.

Properties

eventStream → Stream<SyncEvent<T>>
Public event streams - filtered views of the main event stream
no setter
hashCode → int
The hash code for this object.
no setterinherited
localAdapter → LocalAdapter<T>
Access to the local adapter for direct operations if needed.
no setter
onConflict → Stream<ConflictDetectedEvent<T>>
Stream of conflict detected events.
no setter
onDataChange → Stream<DataChangeEvent<T>>
Emits when local data changes (create, update, delete).
no setter
onError → Stream<SyncErrorEvent<T>>
Stream of sync error events.
no setter
onInit → Stream<InitialSyncEvent<T>>
Emits initial data automatically upon first subscription.
no setter
onSyncCompleted → Stream<SyncCompletedEvent<T>>
Stream of sync completed events.
no setter
onSyncProgress → Stream<SyncProgressEvent<T>>
Stream of sync progress events.
no setter
onSyncStarted → Stream<SyncStartedEvent<T>>
Stream of sync started events.
no setter
onUserSwitched → Stream<UserSwitchedEvent<T>>
Stream of user switched events.
no setter
remoteAdapter → RemoteAdapter<T>
Access to the remote adapter for direct operations if needed.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addMiddleware(SynqMiddleware<T> middleware) → void
Registers a middleware for data transformation pipeline.
cancelSync(String userId) → Future<void>
Cancels an ongoing synchronization for the specified user.
delete(String id, String userId) → Future<void>
Removes an entity from local storage and queues deletion for remote sync.
dispose() → Future<void>
Releases all resources and closes streams.
getAll({String? userId}) → Future<List<T>>
Retrieves all entities for the specified user from local storage.
getById(String id, String userId) → Future<T?>
Retrieves a single entity by ID for the specified user.
getPendingCount(String userId) → Future<int>
Returns the number of pending synchronization operations for the user.
getSyncSnapshot(String userId) → Future<SyncStatusSnapshot>
Retrieves current synchronization status snapshot for the specified user.
getSyncStatistics(String userId) → Future<SyncStatistics>
Retrieves cumulative synchronization statistics.
getSyncStatus(String userId) → Future<SyncStatus>
Gets the current synchronization status for the specified user.
initialize() → Future<void>
Initializes all internal components and establishes change subscriptions.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pauseSync(String userId) → Future<void>
Pauses an ongoing synchronization for the specified user.
resumeSync(String userId) → Future<void>
Resumes a previously paused synchronization for the specified user.
retryFailedOperations(String userId) → Future<void>
Retries all failed synchronization operations by forcing a new sync.
save(T item, String userId) → Future<T>
Persists an entity to local storage and queues for remote synchronization.
startAutoSync(String userId, {Duration? interval}) → void
Starts automatic periodic synchronization for the specified user.
stopAutoSync({String? userId}) → void
Stops automatic synchronization for one or all users.
switchUser({required String? oldUserId, required String newUserId, UserSwitchStrategy? strategy}) → Future<UserSwitchResult>
Switches the active user with configurable handling of unsynced data.
sync(String userId, {bool force = false, SyncOptions? options}) → Future<SyncResult>
Executes a full synchronization cycle for the specified user.
toString() → String
A string representation of this object.
inherited

Operators

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