Skip to content

Latest commit

 

History

History
83 lines (55 loc) · 1.99 KB

File metadata and controls

83 lines (55 loc) · 1.99 KB

Scroll-to-index inside a ListView

Ever needed to open a new page with a ListView and immediately scroll to a given item by index?

This is hard to do if all the items can have different heights.

Luckily, the scroll_to_index package can help.


To use it, declare an AutoScrollController inside your State class.

Then, inside initState, scroll to the desired index.

The controller will use the suggestedRowHeight to scroll to the approximate location, calculate the exact offset, and animate to it.


Finally, wrap your list tiles with an AutoScrollTag, passing the correct key, controller, and index values.

From now on, you can use the controller to scroll to any item by index. ✨


Found this useful? Show some love and share the original tweet


Previous Next
Preloading SVG assets in Flutter Logging HTTP status codes with emojis