quire-io / scroll-to-index

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

How to get current list item Index on scroll? #50

Closed imSanjaySoni closed 3 years ago

jerrywell commented 3 years ago

dup of https://github.com/quire-io/scroll-to-index/issues/40

imSanjaySoni commented 3 years ago
 scroll_to_index: ^1.0.0

void listenPosition() {
  scrollController.addListener(() {
    final int currentIndex = scrollController.currentTagIndexInViewport(
        preferPosition: AutoScrollPosition.begin);
    AutoScrollTagState asts = scrollController.tagMap[currentIndex];
  });
}

Error:

A value of type 'dynamic' can't be assigned to a variable of type 'int'.
Try changing the type of the variable, or casting the right-hand type to 'int'.dart(invalid_assignment)
The method 'currentTagIndexInViewport' isn't defined for the type 'AutoScrollController'.
Try correcting the name to the name of an existing method, or defining a method named 'currentTagIndexInViewport'.dart(undefined_method)
jerrywell commented 3 years ago

try this way. https://github.com/flutter/flutter/issues/19941#issuecomment-486950990

imSanjaySoni commented 3 years ago

try this way. flutter/flutter#19941 (comment)

@jerrywell could you please explain this in simpler way. I am not getting it, or can you tag other example.