Closed Nulligma closed 3 years ago
I'm having a similar problem, I also tried removePageRequestListener()
and it didn't help me either.
Hi @Nulligma and @michael-woolsey . The solution to your problem is detailed here: https://github.com/EdsonBueno/infinite_scroll_pagination/pull/7 Thank you, feel free to ping me in our chat if you still have any problems.
I added the below condition check immediately after Future call
if (mounted) {
}
Future<void> _fetchPage(int pageKey) async {
final pageSize = 10;
final newItems = await RemoteAPI.getFoosByStatus(
widget.status,
limit: pageSize,
offset: pageKey,
);
if (mounted) {
final isLastPage = newItems.length < pageSize;
if (isLastPage) {
_pagingController.appendLastPage(newItems);
} else {
final nextPageKey = pageKey + newItems.length;
_pagingController.appendPage(newItems, nextPageKey);
}}
}
This worked for me.. Hope it will help someone
what happens in case where the pagingController is inside a BLoC, how to dispose it then..
void onFindAll(GetReservationsFindAll getReservationsFindAll,
Emitter<ReservationsFindAllState> emit) async {
emit(const ReservationsLoading());
String? nextStartDate;
ReservationsFindAllDto? reservationsFindAllDto =
getReservationsFindAll.reservationsFindAllDto;
if (getReservationsFindAll.isFilterClicked != null &&
getReservationsFindAll.isFilterClicked! == true) {
resetPageController();
} else {
nextStartDate = await _secureStorage.getReservationsNextStartDate();
}
ReservationsFindAllDto? newReservationsFindAllDto = ReservationsFindAllDto(
filterReservationsEnum: reservationsFindAllDto?.filterReservationsEnum,
limit: reservationsFindAllDto?.limit,
page: reservationsFindAllDto?.page ?? 1,
nextStartDate: nextStartDate);
final dataState =
await _findAllUseCase.call(params: newReservationsFindAllDto);
if (dataState is DataSuccess) {
final newData = dataState.data!;
final isLastPage = newData.reservations!.isEmpty;
final int page =
getReservationsFindAll.reservationsFindAllDto?.page != null
? getReservationsFindAll.reservationsFindAllDto!.page
: 1;
if (isLastPage) {
_pagingController.appendLastPage(newData.reservations!);
} else {
_pagingController.appendPage(newData.reservations!, page + 1);
}
emit(ReservationsLoaded(newData.reservations!));
}
if (dataState is DataFailed) {
emit(ReservationsError(dataState.exception!));
}
}
If I use a TabBar and both tabs have infinite scroll then if I switch tabs between pages are getting fetched then I following error
I dont get any error if I wait for page to fetch
I tried removing Listener but still get the same error