SyncStrategy<T> class abstract

Strategy interface for offline-first synchronization.

Defines HOW local changes are pushed to a remote data source and HOW remote changes are pulled to local. Injected into sync-enabled repositories alongside local/remote datasources.

This is analogous to CachePolicy for cached repositories — it is the swappable strategy that controls non-CRUD behavior.

Example implementations

Usage in generated repositories

class DataProductRepository implements ProductRepository {
  DataProductRepository(
    this._localDataSource,
    this._remoteDataSource,
    this._syncMetadataStore,
    this._syncStrategy,   // ← SyncStrategy<Product>
  );

  @override
  Future<Product> create(Product product) async {
    final saved = await _localDataSource.create(product);
    await _syncStrategy.markPending(saved.id);
    return saved;
  }

  Future<void> syncPending({CancelToken? cancelToken}) {
    return _syncStrategy.syncPending(cancelToken: cancelToken);
  }
}
Implementers

Constructors

SyncStrategy()

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

getPendingCount() Future<int>
Get count of records pending sync.
getSyncStatus(String key) Future<SyncStatus>
Get sync status for a specific record by key.
markDeleted(String key) Future<void>
Mark a record as deleted (tombstone).
markPending(String key, {SyncOperation operation}) Future<void>
Mark a record as pending sync.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pullRemote({CancelToken? cancelToken}) Future<void>
Pull remote data and merge into local storage.
syncFailed({CancelToken? cancelToken}) Future<void>
Retry all previously failed records.
syncPending({CancelToken? cancelToken}) Future<void>
Push all pending local changes to the remote data source.
toString() String
A string representation of this object.
inherited

Operators

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