ok i decided to use
ScrollablePositionedList.builder
https://pub.dev/packages/scrollable_positioned_list
instead of ListView.builder
for more controlling of the index navigation ..
we know that ScrollablePositionedList.builder
use ItemScrollController()
instead of ScrollController()
using ScrollController()
we can do the following to detect if we reach the top list or bottom
ScrollController scrollController= ScrollController();
scrollController.addListener(() {
if(scrollController.position.atEdge){
if (scrollController.position.pixels == 0) {
///we arrive to the end
}
}else{
///we arrive to the top
}
}
});
but how could i do the same with using ScrollablePositionedList.builder
that use ItemScrollController()
so i tried to do this
ItemScrollController scrollController = ItemScrollController();
final listener = ItemPositionsListener.create();
listener.itemPositions.addListener(() {
listener.itemPositions.value // here all what i get .. i cannot see any
position.atEdge or pixels like normal ScrollController
});
really does it not support the detection of top list or bottom or something went wrong with me ? thanks
CodePudding user response:
You can check
- if the value of
itemPositionsListener.itemPositions.value.first.index
is 0
to say it is on top. And to check
- if the value of
${itemPositionsListener.itemPositions.value.last.index}
= list.length - 1
to say it reaches the bottom.
itemPositionsListener.itemPositions.addListener(() {
print(
'====current first ${itemPositionsListener.itemPositions.value.first.index}====');
print(
'====current last ${itemPositionsListener.itemPositions.value.last.index}====');
});