fetchNextPage method
Function to fetch next page data
If return list data is empty, indicator 'hasNextPage' will set false
Implementation
Future<void> fetchNextPage({
/// This function is for passing data from response fetch data to list
required Future<List<T>> Function() fetchApi,
/// This function for check if data already selected before
bool Function(T)? checkDataIsSelected,
}) async {
if (!hasNextPage) {
isLoadingNextPage = false;
if (!_disposed) {
notifyListeners();
refreshStateParentWidget();
}
}
if (isLoadingNextPage) return;
isLoadingNextPage = true;
if (!_disposed) {
notifyListeners();
refreshStateParentWidget();
}
try {
final list = await fetchApi();
isLoadingNextPage = false;
if (!_disposed) {
notifyListeners();
}
addItemList(list, checkDataIsSelected: checkDataIsSelected);
} catch (e) {
isLoadingNextPage = false;
if (!_disposed) {
notifyListeners();
refreshStateParentWidget();
}
}
}