loadPage method
Request load page for Data Source
Implementation
Future<List<ItemType>> loadPage(
{bool isRefresh = false, PageKeyType? newKey}) async {
if (currentKey == null || isRefresh) {
if (_cancelableOperation != null && !_cancelableOperation!.isCompleted) {
_cancelableOperation!.cancel();
}
_cancelableOperation = CancelableOperation.fromFuture(
loadInitial(pageSize, refreshKey: newKey));
final results = await _cancelableOperation!.valueOrCancellation();
isEndList = ((results?.item1.length ?? 0) < pageSize);
currentKey = results?.item2;
return results?.item1 ?? [];
} else {
_cancelableOperation =
CancelableOperation.fromFuture(loadPageAfter(currentKey!, pageSize));
final results = await _cancelableOperation!.valueOrCancellation();
// final results = await loadPageAfter(currentKey as PageKeyType, pageSize);
currentKey = results?.item2;
isEndList = ((results?.item1.length ?? 0) < pageSize);
return results?.item1 ?? [];
}
}