I have a CustomPaint
that needs to be a 1:1 square, and I need to put this in a Row
. The horizontal and vertical space available can vary, so I need both the length and width of the square to be the smallest maximum constraint.
How can I achieve this behaviour?
I've tried using LayoutBuilder
for this:
Row(
children: [
...,
LayoutBuilder(
builder: (context, constraints) {
final size = min(constraints.maxWidth, constraints.maxHeight);
return SizedBox(
width: size,
height: Size,
child: CustomPaint(...),
),
},
),
]
),
This, however, doesn't work, because Row
provides unbounded horizontal constraints (maxWidth == double.infinity
). Using the FittedBox
widget also fails for the same reason.
Wrapping the LayoutBuilder
in an Expanded
widget provides it with a bounded maximum width, but I need to have another widget next to it in the Row
, so this is not appropriate. Flexible
behaves like Expanded
in this case, as well.