Sam
Sam

Reputation: 99

alignment: Alignment.center, isnt aligning the image in center

i am trying to align the image in center of the screen but it not working , can someone help me understand whats wrong with the code? and why the alignment: Alignment.center, isnt working ?

Please have a look at the image i attached below , the logo is painted towards the left of the screen and not in the center

enter image description here

            Row(
          children: <Widget>[
            Container(
              alignment: Alignment.center,
              child:Container(
              child: Image.asset('assets/logo.png'),
              height: 200.0,
              ),
            ),

          ],
        ),

Upvotes: 0

Views: 1517

Answers (2)

Javeed Ishaq
Javeed Ishaq

Reputation: 7105

Yes, Marcel Dz is suggesting correct add mainAxisAlignment:MainAxisAlignment.center, for row to show image in center

 Row(
      mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
                  alignment: Alignment.center,
                  child: Container(
                    child: Image.asset('assets/images/logo.png'),
                    height: 200.0,
                  ),
                ),
              ],
            ),

enter image description here

Upvotes: 2

Marcel Dz
Marcel Dz

Reputation: 2714

You can remove the alignment from your Container() and manage it with your parent widget Row() by using MainAxisAlignment.center

Row(
      mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
...

Upvotes: 4

Related Questions