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

Categories

0 votes
1.7k 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...