Is there a way we can use ScrollController.position.pixels to know the scrolling index of a listview in flutter? I'm trying to restore the last scrolling index between app restarts.
Asked
Active
Viewed 400 times
0
-
Does your `Listview` item have the same height? You like to save scrollPosition on phone storage? – Md. Yeasin Sheikh Sep 05 '21 at 03:25
-
No.. list item has different height. I'd like to save index in shared preferences which I can retrieve later. – Noor Sep 05 '21 at 03:35
1 Answers
0
You can use the flutter_scrollview_observer lib to implement your desired functionality without invasivity
Create and use instance of ListView
normally.
ListView _buildListView() {
return ListView.separated(
...
);
}
Pass the ListView
instance to the ListViewObserver
, then you can obtain the desired result in the onObserve
callback
ListViewObserver(
child: _buildListView(),
onObserve: (resultModel) {
print('firstChild.index -- ${resultModel.firstChild?.index}');
print('displaying -- ${resultModel.displayingChildIndexList}');
},
)

LinXunFeng
- 41
- 3