Specific min and max size for expanded widgets in Column

情到浓时终转凉″ 提交于 2019-12-24 08:59:14

问题


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 the rest available to other widgets.

EDIT:

Because I got two probably misleading answers, I’d like to clarify. I want something like this:

Expanded(flex: 1, minSize: 50, maxSize: 200, child: ...)

That means that this expanded widget takes a flex of 1, but should never be smaller than 50 and bigger than 200.


回答1:


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),
    ),
  ],
),



回答2:


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")
      ],
    )


来源:https://stackoverflow.com/questions/56417186/specific-min-and-max-size-for-expanded-widgets-in-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!