quire-io / scroll-to-index

scroll to index with fixed/variable row height inside Flutter scrollable widget
MIT License
518 stars 105 forks source link

How do I get a current Index #90

Open rajvarasdiya opened 2 years ago

rajvarasdiya commented 2 years ago

My concern is how do I get a currentIndex, while user is scrolling.

I saw on AutoScrollController we don't get a index, will you please tell me how can I get a current Index ??

LinXunFeng commented 1 year ago

You can use flutter_scrollview_observer to observe ScrollView, it will tell you which items are being displayed and thus know the currentIndex from resultModel.firstChild?.index.

ListViewObserver(
  child: _buildListView(),
  onObserve: (resultModel) {
    print('firstChild.index -- ${resultModel.firstChild?.index}');
    print('displaying -- ${resultModel.displayingChildIndexList}');
  },
)