Scroll Position Lost on State Change in ListView โ€” with Workaround Solution

Widgets & Design
Resolved

Edited on June 4.

I have already solved this problem, but I would like to understand why my workaround works:

Problem:

I have a ListView that displays items with a background color conditionally set based on whether a document reference matches a Page State. When a container inside a list item is tapped, it sets the Page State to that document reference โ€” which works as expected visually. It also passes the document reference into a child component, which has a backend query to fetch details about that document.

However, the issue is that the backend query triggers a full rebuild of the page, causing the ListView to lose its scroll position and jump back to the top.

What have you tried so far?

Workaround That Solved It:

I changed the component to receive the the document (not just the reference) as a parameter to it. I kept the same logic to highlight the selected item based on the Page State. There is no corresponding backend query, and this preserves the scroll position when the item is tapped. Albeit, at the expense of 'live' data from the document.

Can anyone explain why this is the case?

Also, to Flutterflow devs, please add a scroll-to-index function for ListViews. I know there are pubspec packages, but this would make life a lot easier.

Did you check FlutterFlow's Documentation for this topic?
No
2 replies