Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center column and row item in Flutter?

People also ask

How do you center an item in column Flutter?

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.

How do you center horizontally and vertically in Flutter?

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: [...
                           .
                           ]