cacheMoreRecords method
Fetches more records from remote and adds them to list of cached records. Supposed to be used with list views.
Implementation
Future<void> cacheMoreRecords() async {
if (isLoadingMore) return;
isLoadingMore = true;
offset += limit;
try {
final res = await searchRead();
isLoadingMore = false;
if (res.isEmpty) return;
var cachedRecords = _cachedRecords;
for (Map<String, dynamic> item in res) {
var record = createRecordFromJson(item);
cachedRecords.add(record);
await cachePut(record);
}
await env.cache.delete(recordIdsCacheKey);
await env.cache
.put(recordIdsCacheKey, cachedRecords.map((e) => e.id).toList());
latestRecords = cachedRecords;
_recordStreamAdd(latestRecords);
} on Exception {
isLoadingMore = false;
env.logger.d('$modelName: frontend_get_requests: OdooException}');
}
}