PushOnlySyncStrategy<T> class

Default push-only synchronization strategy.

Pushes local changes to a remote data source but does not pull remote changes. Processes records with SyncStatus.pending or SyncStatus.failed in batches of SyncConfig.batchSize, with retry and exponential backoff governed by SyncConfig.maxRetries.

Tombstones (records marked for deletion) are processed first, before live record synchronization.

Callback-based design

This strategy lives in the framework and cannot know about specific entity types or datasource interfaces. Instead, it accepts callback functions that the generated code wires up at runtime:

  • _fetchLocal: reads local entities by key
  • _createRemote: creates an entity on the remote
  • _updateRemote: updates an entity on the remote
  • _deleteRemote: deletes an entity from the remote by key
  • _keyResolver: extracts the sync key from an entity

Example (generated wiring)

final strategy = PushOnlySyncStrategy<Product>(
  fetchLocal: (keys) => localDataSource.getByIds(keys),
  createRemote: (product) => remoteDataSource.create(product),
  updateRemote: (product) => remoteDataSource.update(product),
  deleteRemote: (id) => remoteDataSource.delete(id),
  keyResolver: (product) => product.id,
  metadataStore: syncMetadataStore,
);
Inheritance
Mixed-in types
Implementers

Constructors

PushOnlySyncStrategy({required Future<List<T>> fetchLocal(List<String> keys), required Future<T> createRemote(T entity), required Future<T> updateRemote(T entity), required Future<void> deleteRemote(String key), required String keyResolver(T entity), required SyncMetadataStore metadataStore, SyncConfig config = const SyncConfig()})

Properties

fetchLocal → Future<List<T>> Function(List<String> keys)
Protected: fetch local entities by keys.
no setter
hashCode → int
The hash code for this object.
no setterinherited
keyResolver → String Function(T entity)
Protected: resolve sync key from an entity.
no setter
logger → Logger
Logger instance for this class.
no setterinherited
metadataStore → SyncMetadataStore
Protected: metadata store.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

getPendingCount() → Future<int>
Get count of records pending sync.
override
getSyncStatus(String key) → Future<SyncStatus>
Get sync status for a specific record by key.
override
markDeleted(String key) → Future<void>
Mark a record as deleted (tombstone).
override
markPending(String key, {SyncOperation operation = SyncOperation.create}) → Future<void>
Mark a record as pending sync.
override
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.
override
syncFailed({CancelToken? cancelToken}) → Future<void>
Retry all previously failed records.
override
syncPending({CancelToken? cancelToken}) → Future<void>
Push all pending local changes to the remote data source.
override
toString() → String
A string representation of this object.
inherited

Operators

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