I have a ListView
of cards. Clicking on a card takes you to a detailed page. I push the screen using context.pushNamed
via GoRouter
. Upon clicking on back <
, I am always taken to the beginning of the list.
I want to preserve the scrolling offset when back to the list view page.
2
Answers
You can prevent the screen from
rebuilding
when you navigate back to the listview screen by using thebuildWhen
property from the flutter_bloc package.You can pass the offset of the ListView (using a ScrollController to handle that value), or you can use the id of the detailed item itself, when going back use the result parameter and pass the previous offset or id of the item and use the ScrollController from the ListView to scroll to that position (either directly the offset or the position of the item in the list).