Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

flutter - Specific min and max size for expanded widgets in Column

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...