Flutter - ListView inside on a TabBarView loses its scroll position

前端 未结 7 1530
误落风尘
误落风尘 2021-01-30 11:07

I have a very simple Flutter app with a TabBarView with two views (Tab 1 and Tab 2), one of them (Tab 1) has

7条回答
  •  醉梦人生
    2021-01-30 11:29

    Can't add a comment, so left it as answer.

    If you using PageStorageKey, have a lot of items in the ListView, scroll down plenty items and have lag on tab switch, the solution is to provide itemExtent to ListView.

    As I understand, without itemExtent ListView don't know which items immediately show, because using PageStorageKey cashed only position in pixels, and ListView need calculate height of all items scrolled from top. In another hand, with itemExtent ListView can easily calculate item to show, for example: index = cashedPositionInPixels / itemExtent.

提交回复
热议问题