getFromId method
Gets a model from id
This function returns the model if is in repositoryMap. If not, then it gets the model from the database and stores it into repositoryMap
- Set
cache
to true to get the model from the cache of the database. - Set
refreshRepoData
to always get the data from the database and rewrite it into repositoryMap - Set
notify
to call_update()
function and notify to all listener that is a change in the model withid
in repositoryMap. This is only when the model is obtained from the database and estored in repositoryMap.
Implementation
Future<Model?> getFromId(
Id id, {
bool cache = false,
bool refreshRepoData = false,
bool notify = false,
}) async {
if (!refreshRepoData) {
Model? res = repositoryMap[id];
if (res != null) return res;
}
Query query =
collectionReference!.where(FieldPath.documentId, isEqualTo: id);
QuerySnapshot? queryRes =
await PauloniaDocumentService.runQuery(query, cache);
if (queryRes == null || queryRes.docs.isEmpty) return null;
Model res = (await getFromDocSnapList(queryRes.docs)).first;
repositoryMap[id] = res;
if (notify) update(RepoUpdateType.get, ids: [id]);
return res;
}