Home > Enterprise >  Align center flutter
Align center flutter

Time:11-16

why the container does not align to the center? it always align to the left although I specified that it to align to the center.

Row(
              
              children: <Widget>[
                Align(
                  alignment: Alignment.center,
                  child: Container(
                    width: 250,
                    color: Colors.grey,
                     
                    padding: const EdgeInsets.all(3.0),

                    child: FittedBox(
                      fit: BoxFit.contain,
                      child: PostBody(),
                    ),
                  ),
                )
              ],
            ),

CodePudding user response:

Because of the Row. It defaults to MainAxisAlignment.start which is left.

Add this to your Row:

mainAxisAlignment: MainAxisAlignment.center,

And you can remove the Align.

CodePudding user response:

You can try this solution :

Row(
  mainAxisAlignment: MainAxisAlignment.center,
  children: <Widget>[
    Container(
      width: 250,
      color: Colors.grey,
      padding: const EdgeInsets.all(3.0),
      child: FittedBox(
        fit: BoxFit.contain,
        child: PostBody(),
      ),
    )
  ],
),
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

I think the error in align Widget because the container already have align you can use it inside a container and remove Align widget if you need it in the center of screen like

alignment = Alignment.center

if you want it in the center of row you can use

mainAxisAlignment = MainAxisAlignment.center

CodePudding user response:

Try below code hope its helpful to you. just change your widget instead of my widget.

  1. Refer Row widget image

  • Related