how to place a listview inside a SingleChildScrollView but prevent them from scrolling separately?

后端 未结 6 905
我在风中等你
我在风中等你 2020-12-15 17:10

I have a widget tree like this:

SingleChildScrollView
   Column
     Container
       ListView(or GridView)

the problem is that when my wid

6条回答
  •  时光取名叫无心
    2020-12-15 18:03

    Why it is happening?

    It happens because Column and ListView both take the entire space of screen individually which is there default behavior.

    How to solve the problem?

    To solve the above problem we have to disable scrolling of Listview, This can be possible by shrinkWrap and physics property

    shrinkWrap:true - It forces ListView to take only the required space, not the entire screen.

    physics: NeverScrollableScrollPhysics() - It disables scrolling functionality of ListView, which means now we have only SingleChildScrollView who provide the scrolling functionality.

    Code:

    SingleChildScrollView
       Column
         Container
            ListView(
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                    //...
                    )
    

    https://medium.com/flutterworld/flutter-problem-listview-vs-column-singlechildscrollview-43fdde0fa355

    Note: Above ListView behaviour will be also applied for GridView.

提交回复
热议问题