I have a Column
with some widgets, and I want the last one of those widgets to be at most 100px tall, but if there's not enough room on the screen then it should be able to shrink down to 0px.
So if this is my layout, I want the part below the black square to be at most 100px, but if the screen is too small I want it to shrink accordingly.
Center(
child: Container(
height: double.infinity,
width: double.infinity,
color: Colors.blue,
child: Column(
children: <Widget>[
SizedBox(height: 20),
Container(color: Colors.white, width: 200, height: 200),
SizedBox(height: 20),
Container(color: Colors.grey, width: 400, height: 100),
Expanded(child: SizedBox(height: double.infinity)),
SizedBox(height: 50),
Container(color: Colors.black, width: 200, height: 200),
SizedBox(height: 100),
],
),
),
);
Notice the Expanded
in the middle - this makes the distance between the grey and black containers adjust to fill the screen height. The problem is that some devices have a screen that is so small that this Expanded
becomes 0px, and then the bottom SizedBox
will overflow. Hence why I want it to adjust, but never become taller than 100px.
Even after reading through the documentation about constraints, I still don't know how to achieve this.