SmartRepository<T> class

Offline-first repository that coordinates local cache, remote API, and sync queue.

Use save for creating new entities (calls RemoteDataSource.create when online). Use update for modifying existing entities (calls RemoteDataSource.update when online). Use delete to remove an entity locally and on the server (or enqueue when offline).

Constructors

SmartRepository({required RemoteDataSource<T> remoteSource, required LocalDataSource<T> localSource, required ConnectivityService connectivity, required OfflineQueue<T> offlineQueue, FetchPolicy fetchPolicy = FetchPolicy.cacheFirst})

Properties

connectivity → ConnectivityService
final
fetchPolicy → FetchPolicy
final
hashCode → int
The hash code for this object.
no setterinherited
localSource → LocalDataSource<T>
final
offlineQueue → OfflineQueue<T>
final
remoteSource → RemoteDataSource<T>
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

delete(String id) → Future<void>
Deletes an entity locally and schedules remote deletion (or enqueues when offline).
getAll({FetchPolicy? policy}) → Future<List<T>>
Returns all entities. policy overrides the default fetchPolicy: FetchPolicy.cacheOnly, FetchPolicy.networkOnly, FetchPolicy.cacheFirst, FetchPolicy.networkFirst, FetchPolicy.staleWhileRevalidate.
getById(String id, {FetchPolicy? policy}) → Future<T?>
Returns a single entity by id, or null if not found. Uses policy or the default fetchPolicy; see getAll for behavior per policy.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
save(String id, T item) → Future<void>
Creates an entity: saves locally and calls RemoteDataSource.create when online. If offline or the remote call fails, the action is enqueued for later sync.
toString() → String
A string representation of this object.
inherited
update(String id, T item) → Future<void>
Updates an entity: saves locally and calls RemoteDataSource.update when online. If offline or the remote call fails, the action is enqueued for later sync.

Operators

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