Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 550
user3612643 Avatar asked Jun 02 '19 17:06

user3612643


2 Answers

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),
    ),
  ],
),
like image 101
Hugo Passos Avatar answered Nov 09 '22 11:11

Hugo Passos


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

like image 8
Leon Avatar answered Nov 09 '22 12:11

Leon