OfflineFirstWithRestRepository class abstract

Ensures the remoteProvider is a RestProvider. All requests to and from the remoteProvider pass through a seperate SQLite queue. If the app is unable to make contact with the remoteProvider, the queue automatically retries in sequence until it receives a response. Please note that a response may still be an error code such as 404 or 500. The queue is only concerned with connectivity.

OfflineFirstWithRestRepository should accept a type argument such as <_RepositoryModel extends OfflineFirstWithRestModel>, however, this causes a type bound error on runtime. The argument should be reintroduced with a future version of the compiler/analyzer.

Constructors

OfflineFirstWithRestRepository({bool? autoHydrate, String? loggerName, MemoryCacheProvider? memoryCacheProvider, required Set<Migration> migrations, required RequestSqliteCacheManager<Request> offlineQueueManager, List<int> reattemptForStatusCodes = const [404, 501, 502, 503, 504], required RestProvider restProvider, required SqliteProvider sqliteProvider, bool throwTunnelNotFoundExceptions = false})

Properties

autoHydrate bool
Refetch results in the background from remote source when any request is made. Defaults to false.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
logger → Logger
User for low-level debugging. The logger name can be defined in the default constructor; it defaults to OfflineFirstRepository.
finalinherited
memoryCacheProvider → MemoryCacheProvider
The first data source to speed up otherwise taxing queries. Only caches specified models.
finalinherited
migrationManager → MigrationManager
finalinherited
offlineRequestQueue ↔ RestOfflineRequestQueue
getter/setter pair
reattemptForStatusCodes List<int>
If the response returned from the client is one of these error codes, the request will not be removed from the queue. For example, if the result of a request produces a 404 status code response (such as in a Tunnel not found exception), the request will be reattempted. If upsert response matches this status code, it will not throw an exception.
final
remoteProvider RestProvider
The type declaration is important here for the rare circumstances that require interfacting with RestProvider's client directly.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sqliteProvider → SqliteProvider
The local data source utilized before every operation.
finalinherited
throwTunnelNotFoundExceptions bool
When the device is connected but the URL is unreachable, the response will begin with "Tunnel" and ends with "not found".
final

Methods

applyPolicyToQuery(Query? query, {OfflineFirstDeletePolicy? delete, OfflineFirstGetPolicy? get, OfflineFirstUpsertPolicy? upsert}) → Query?
As some remote provider's may utilize an OfflineFirstPolicy from the request, this composes the policy to the query (such as in the providerArgs).
delete<_Model extends OfflineFirstWithRestModel>(_Model instance, {OfflineFirstDeletePolicy policy = OfflineFirstDeletePolicy.optimisticLocal, Query? query}) Future<bool>
Remove a model from SQLite and the remoteProvider
exists<_Model extends _RepositoryModel>({Query? query}) Future<bool>
Check if a _Model is accessible locally. First checks if there's a matching query in memoryCacheProvider and then check sqliteProvider. Does not query remoteProvider.
inherited
get<_Model extends OfflineFirstWithRestModel>({OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist, Query? query, bool seedOnly = false}) Future<List<_Model>>
Load association from SQLite first; if the _Model hasn't been loaded previously, fetch it from remoteProvider and hydrate SQLite. For available query providerArgs see remoteProvider#get SqliteProvider.get.
getAssociation<_Model extends _RepositoryModel>(Query query) Future<List<_Model>?>
Used exclusively by the OfflineFirstAdapter. If there are no results, returns null.
inherited
getBatched<_Model extends _RepositoryModel>({int batchSize = 50, OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist, Query? query, bool seedOnly = false}) Future<List<_Model>>
Get all results in series of batchSizes (defaults to 50). Useful for large queries or remote results.
inherited
hydrate<_Model extends OfflineFirstWithRestModel>({bool deserializeSqlite = true, Query? query}) Future<List<_Model>>
Fetch and store results from remoteProvider into SQLite and the memory cache.
initialize() Future<void>
Prepare the environment for future repository functions. It is recommended to call this method within a StatefulWidget's initState to ensure it is only invoked once. It is not automatically invoked.
migrate() Future<void>
Update SQLite structure with only new migrations.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() Future<void>
Destroys all local records - specifically, memoryCache and sqliteProvider's data sources.
inherited
storeRemoteResults<_Model extends _RepositoryModel>(List<_Model> models) Future<List<_Model>>
Save response results to SQLite.
inherited
toString() String
A string representation of this object.
inherited
upsert<_Model extends OfflineFirstWithRestModel>(_Model instance, {OfflineFirstUpsertPolicy policy = OfflineFirstUpsertPolicy.optimisticLocal, Query? query, bool throwOnReattemptStatusCodes = false}) Future<_Model>
throwOnReattemptStatusCodes - when true, the repository will throw an OfflineFirstException for responses that include a code within reattemptForStatusCodes. Defaults false.

Operators

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