How can I tightly wrap a Column of widgets inside a Card?

前端 未结 2 393
误落风尘
误落风尘 2021-02-06 20:34

I have a page of my app that consists solely of a Card that holds a Column at the end of which is a MaterialList. Even if my list only has

相关标签:
2条回答
  • 2021-02-06 21:29

    By default, Column expands to fill the maximum vertical space. You can change this behavior by setting the mainAxisSize property to MainAxisSize.min, which causes the Column to take up only the minimum amount of vertical space it needs to fit its children.

    0 讨论(0)
  • 2021-02-06 21:41

    Wrap widget may come to rescue if anyone wants to shrink its list, which exacts similar to @Adam answer

    body: Container(
            child: Card(
              child: Wrap(
                direction: Axis.vertical,
                spacing: 10,
                children: <Widget>[
                  Text('One'),
                  Text('Two'),
                  Text('Three'),
                  Text('Four'),
                ],
              ),
            ),
          ), 
    

    but this Wrap can do the job of both Row & Column if you add Column for Axis.vertical & Row for Axis.Horizontal. Also you can add equal spacing to all inbetween widgets which is missing in Column & Row

    0 讨论(0)
提交回复
热议问题