Specific min and max size for expanded widgets in Column

后端 未结 3 990
闹比i
闹比i 2021-01-11 22:21

I have a Column with a set of Expanded widgets.

Is there a way to control the range in which they expand? I want one widget to expand only to a certain size and make

相关标签:
3条回答
  • 2021-01-11 22:41

    You are looking for ConstrainedBox.

    You can create a List of Widgets with both ConstrainedBox and Expanded, as following:

    Row(
      children: [
        ConstrainedBox(
          child: Container(color: Colors.red),
          constraints: BoxConstraints(
            minWidth: 50,
            maxWidth: 100,
          ),
        ),
        Expanded(
          child: Container(color: Colors.green),
        ),
        Expanded(
          child: Container(color: Colors.blue),
        ),
      ],
    ),
    
    0 讨论(0)
  • 2021-01-11 22:58

    You can use constraint box to use the range of min and max width like below:

    Row(
          children: <Widget>[
            Text("Text 1"),
            ConstrainedBox(
              constraints: BoxConstraints(maxHeight: 30, maxWidth: 40, minWidth: 30),
            ),
            Text("Text 2")
          ],
        )
    
    0 讨论(0)
  • 2021-01-11 23:03

    When using ConstrainedBox in Rows my minWidth is ignored and the maxWidth is used as a fixed size.

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