storeRemoteResults<TModel extends RepositoryModel> method
- @protected
- @visibleForTesting
Save response results to SQLite.
When true
, shouldNotify
will check if any subscribers of TModel
are affected by
the new models
. See notifySubscriptionsWithLocalData.
Implementation
@protected
@visibleForTesting
Future<List<TModel>> storeRemoteResults<TModel extends RepositoryModel>(
List<TModel> models, {
bool shouldNotify = true,
}) async {
final modelIds = models.map((m) => sqliteProvider.upsert<TModel>(m, repository: this));
final results = await Future.wait<int?>(modelIds, eagerError: true);
MapEntry modelWithPrimaryKey(index, id) {
final model = models[index];
model.primaryKey = id;
return MapEntry(index, model);
}
final savedResults = results.asMap().map(modelWithPrimaryKey).values.toList().cast<TModel>();
if (shouldNotify) await notifySubscriptionsWithLocalData<TModel>();
return savedResults;
}