In Flutter, to vertically center a child widget inside a Container, you can wrap the child widget with Column and add mainAxisAlignment: MainAxisAlignment. center to it.
You can use the Center widget but it centers both horizontal and vertical. If you have a list of Widgets you can use Column widget and it has a property to center only vertically. mainAxisAlignment with method MainAxisAlignment.
If you want the whole table to be Centered
, use the mainAxisAlignment
property of Column
.
Column
mainAxisAlignment: MainAxisAlignment.center //Center Column contents vertically,
crossAxisAlignment: CrossAxisAlignment.center //Center Column contents horizontally,
Row
mainAxisAlignment: MainAxisAlignment.center //Center Row contents horizontally,
crossAxisAlignment: CrossAxisAlignment.center //Center Row contents vertically,
If you want it to be like in the picture, use
mainAxisAlignment: MainAxisAlignment.spaceEvenly
You can use Spacer
if you want fine grain control.
Column(
children: <Widget>[
Spacer(), // 1st spacer
Widget1(),
Widget2(),
Spacer(), // 2nd spacer
],
)
You can change flex
too using Spacer(flex:2)
use like this
In Colum
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [...
.
]
In Row
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [...
.
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With