I have a layout like this:
Container(
alignment: Alignment.center,
color: Colors.blueGrey,
child: Container(
color: Colors.amber,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 150, // Dummy - actual width is unknown
height: 100,
color: Colors.red,
),
Container(
width: 300, // Dummy - actual width is unknown
height: 100,
color: Colors.green,
)
],
),
),
)
Which produces this layout:
Then I add crossAxisAlignment: CrossAxisAlignment.stretch,
to the Column
, expecting this:
However, what actually happens is this:
Why? How can I achieve my expected result?
2
Answers
Set padding to your root container
stretch
will try to get as much space as possible. You can set the yellow Container width and usestretch
but this is hard-coded. Also you useIntrinsicWidth
over Column widget and it will use max child width , but it has some cost.