Closed clragon closed 3 years ago
Hi @clragon .
I'm not sure what SmartRefresher
is, but I'm guessing it's not from Flutter.
You can do what you want simply by not calling pagingController.refresh()
.
Inside your onRefresh
, call a function you create that will load the first page again and does exactly what you want (e.g. not replacing item if it fails).
If you want to keep the indicator on the screen until items are loaded, you can use this solution.
pagingController.refresh() resets previously loaded content.
authors requested feature "pagingController loading new data, but not emptying the items just yet" is very useful.
@clragon Extends and override these methods to get what you want
class PagingControllerExtent<PageKeyType, ItemType>
extends PagingController<PageKeyType, ItemType> {
PagingControllerExtent({
required super.firstPageKey,
super.invisibleItemsThreshold,
});
/// Whether it is in the state of background refresh
bool background = false;
@override
void refresh({bool background = false}) {
if (background) {
this.background = true;
// Since the state of PagingState has too much influence,
// skip it here and directly notifyPageRequestListeners.
notifyPageRequestListeners(firstPageKey);
} else {
super.refresh();
}
}
@override
void appendPage(List<ItemType> newItems, PageKeyType? nextPageKey) {
// Add judgment here
final previousItems = background ? <ItemType>[] : value.itemList ?? <ItemType>[];
final itemList = previousItems + newItems;
value = PagingState<PageKeyType, ItemType>(
itemList: itemList,
error: null,
nextPageKey: nextPageKey,
);
// reduction
background = false;
}
}
good, I think the default value of 'background' parameter of 'refresh' method better be true!
When using a
SmartRefresher
and callingpagingController.refresh()
inside theonRefresh
method, this will lead to thepagingController
throwing all items away and then loading new ones.This also means, that during the loading, the initial loading screen of the Page is shown. The
SmartRefresher
header is also shown. This means, there are now two loading indicators on the screen.What I would wish as a feature is refreshing with data replacement. This would mean:
refresh(background: true)
)