skip to Main Content

mainAxisAlignment to center causes all 3 widgets as one to become centered.

How do I center the 2nd widget only, and keep the other two widgets beside the middle 2nd widget?

2

Answers


  1. create 4 rows , center the middle one with its own alignment. something like this …

    Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly
      children: 
      [
        Row(children: [...]), // start or end align here if needed
        Row(mainAxisAlignment: MainAxisAlignment.center, children: [...] ),
        Row(children: [...]), // start or end align here if needed
      ],
     ),
    
    Login or Signup to reply.
  2. This would center only the second Container and the first and third would be at the start and end position.

    Row(
          children: 
          [
            Container(),
            Spacer(),
            Container(),
            Spacer(),
            Container(),
          ],
         ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search