Search code examples
fluttercustomscrollview

How to nest a TabBarView's ListView in a CustomScrollView?


The thing I want to layout is like this enter image description here Because I want the ListView scroll with outside , So I want to make the ListView to the SliverListView .

But this will make the error:

A RenderRepaintBoundary expected a child of type RenderBox but received a child of type RenderSliverList.

What's the best practice to do this kind of layout? do I have to change CustomScrollView to NestedScrollView?


Solution

  • Since SliverListView is a Sliver widget, it can only be the direct child of CustomScrollView. Use it inside the TabBarView will cause the above error since TabBarView expect a RenderBox widget, not a Sliver.

    In order to sync the scroll with the CustomScrollView, you can use this property:

    ListView(
        physics: NeverScrollableScrollPhysics(),
        // ... other lines