Flutter : keeping list view index while changing Page View

Paul Boldijar
Mar 9, 2018 · 1 min read

A really annoying issue that I recently found when working with lists in flutter, is that in some cases, you will loose the current scroll position.

Maybe my issue is similar to https://github.com/flutter/flutter/issues/8101 but still, is not working after they fixed it.

In my case, I had to show a page view, with some bottom navigation widget under.

How it looks:

If you look closely you’ll see that the item position is reset.

The code that generates the above UI:

The same issue was reported on stackoverflow and Marcin Szałek came with a solution, that I modified a little bit to be more generic, and be able to reuse in many places, creating a StatefulListView

And in the end, the final code that will save the list position:

Written by

Freelance Android developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade