Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter: Place 2 sized Containers in the middle of a column in a row

I have 2 containers with width and height set to them and a background color (basically a small box). I want to put those 2 containers in the middle or a parent container, on the same row divided to 2 columns in the middle of each column.

I know it sounds confusing. It really isn’t. This is what I want to achieve:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Having the 2 yellow containers in the middle of an imaginary column that takes half the width of the container.

This is my row containing the 2 yellow boxes:

Row(
    children: [
      SwitchPreviewButton(),
      
      SwitchPreviewButton(),
    ],
  );

And this is the yellow box widget:

Widget build(BuildContext context) {
    double width = 10.22;
    double height = 17.32;

    return Container(
      constraints: BoxConstraints(maxWidth: width, maxHeight: height),
      width: width,
      height: height,
      decoration: BoxDecoration(
        color: Colors.yellow, //const Color(0xFFB0B0B0),
        borderRadius: BorderRadius.circular(1.16)
      ),
    );
  }

And this is what I get:

enter image description here

If I try to use Expand and center the Yellow widget takes 100% of available space.

How can I achieve that?

>Solution :

add this to your row

Row(
 mainAxisAlignment: MainAxisAlignment.spaceAround,  //<---- ADD THIS
    children: [
      SwitchPreviewButton(),
      
      SwitchPreviewButton(),
    ],
  );
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading