Hi @zeapo
Try using the value
property from PagingController
:
_pagingController.value = PagingState(
nextPageKey: nextPageKey,
error: null,
itemList: updatedList,
);
Don't mind about reloading the entire list. Flutter will take care of checking what items actually changed.
I don't think you'll lose your scroll position using the method above. Still, if that happens, check out PageStorageKey from Flutter.
same issue @EdsonBueno , If I do something simple like (for testing)
_pagingController.itemList.removeAt(0);
_pagingController.value = PagingState(
nextPageKey: _pagingController.nextPageKey,
error: null,
itemList: _pagingController.itemList,
);
It does not update the view, adding a .toList()
when passing it makes it refresh. Or calling notifyListeners()
on the controller. I dont mind adding toList()
for small lists (my case), but wondering why :)
itemList
from _pagingController
, you don't need to use .value
, just use notifyListeners()
instead
_pagingController.itemList.removeAt(0);
_pagingController.notifyListeners();
this will work as well
toList()
until I find a better way
value
, it will only notify its listeners of the change, if the PagingState
is different from the previous one. Unless you add .toList()
, the reference of the itemList
doesn't change, and so it doesn't know that it actually changed.toList()
or a notifyListeners()
works.
Hi @mban .
Are your items being sorted on the API side? For example, before you get any "YESTERDAY" items, the API has to make sure all "TODAY" items are already delivered to you.
Assuming this is true, the rest isn't that hard.
Inside your itemBuilder
callback, check if the current item is the first of its group by consulting PagingController.itemList
. If it isn't, build and return the list item's widget as always. If it is, return a Column
where the first element is your header and the second is your list item's widget.
ProviderListener(
provider: createCommentProvider,
onChange: (context, state) {
if (state.comment != null) {
state.comment.isNew = true;
_pagingController.itemList.add(state.comment);
}
},
........
invisibleItemThreshold: 1
. Still, I get three pages of length 2 fetched (third one is my last one so can't test more). The first two items are visible (page 1). Next two items are invisible (page 2). Still it fetches a third page, despite just over 2 items being invisible.