I have three ListViews, and on iOS scroll to top scrolls all of them up

Viewed 210

I have the following:

IndexedStack(
  index: index,
  children: [
    Scaffold(
      body: ListView(),
    ),
    Scaffold(
      body: ListView(),
    ),
    Scaffold(
      body: ListView(),
    ),
  ],
)

However, on iOS, it seems that tapping the status bar to scroll to top scrolls all of these lists to the top.

Is there any way to make this behavior work correctly? I tried to add individual controller: _scrollController to each ListView, but that then didn't make the scroll to top work at all (tapping status bar did not scroll the list view).

Any way to make this work?

Update: Thanks to @vandad answer below, also with using key of PageStorageKey on each ListView/ScrollController/etc., it is possible to have the scroll to top functionality again on each individual view.

ListView(
  key: PageStorageKey<String>("GIVE A KEY"),
...
)
1 Answers

Yes you can do that by setting the primary: false property of your other two ListView instances like this:

IndexedStack(
  index: index,
  children: [
    Scaffold(
      body: ListView(),
    ),
    Scaffold(
      body: ListView(
        primary: false,
      ),
    ),
    Scaffold(
      body: ListView(
        primary: false,
      ),
    ),
  ],
)
Related