0

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.

Noor
  • 193
  • 1
  • 2
  • 15

1 Answers1

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