I have a column in which there is textField in the bottom and a Expanded widget taking up the rest of the vertical space above. I want to center a widget inside this expanded that has its own size determined by that widgets children. Now when I try to run this by putting it inside a Center widget, it only centers it horizontally and makes it take up all the vertical space in the expanded. How do I solve this?
Column(
children: [
Expanded(
child: SizedBox(
width: double.maxFinite,
height: double.maxFinite,
child: Center(
child: TaskWidget(),
),
)
),
SizedBox( /* The text field */)
],
),
It seemed that every child of the column was inheriting something that forced the children take up all vertical space and it only centered when I added a column and other expanded widgets to take up that extra vertical space so that it can finally center itself.
Column(
children: [
Expanded(
child: SizedBox(
width: double.maxFinite,
height: double.maxFinite,
child: Column(
children: [
Expanded(child: Container()),
TaskWidget(),
Expanded(child: Container())
],
),
)
),
SizedBox( /* The text field */)
],
),
but I feel like this is a very incomplete solution. How can I do something that the column doesnt force the children to take up all vertical space? is there some widget I can use that doesnt pass down this to its children?
thanks everyone in advance!
2
Answers
The
mainAxisSize
property of aColumn
defaults toMainAxisSize.max
, set it toMainAxisSize.min
.You don’t need the SizedBox for centering:
If above does not work for you somehow, try this: