Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Column align items to have the same width

I'm trying to align the widgets inside the column to be in the center with CrossAxisAlignment.center but I also want that the Widgets have the same width. How can I achieve this?

like image 456
TheRedhat Avatar asked Aug 04 '18 10:08

TheRedhat


People also ask

How do you give equal width in Row Flutter?

Change width of a row Row normally takes available space and we can control that by wrapping inside a Container or SizedBox widget. You can wrap the Row inside the Container and add width to the container. Then the Row will take the same width as a Container.

Does align work in Column Flutter?

Alignment Properties:In column, children are aligned from top to bottom. Main Axis is vertical and the Cross Axis is horizontal. MainAxisAlignment aligns its children vertically and CrossAxisAlignment aligns horizontally in that Column.

How do you Margin a Column in Flutter?

To set Margin for Container widget in Flutter, set margin property wit the required EdgeInsets value. We can set margin for top, right, bottom, and left with separate values using EdgeInsets. fromLTRB(), or a set a same value for margin on all sides.


1 Answers

you can get something similar to that by setting the CrossAxisAlignment to stretch and then wrap the Column in a IntrinsicWidth and if you want to give them a specific width use the stepWidth property

Center(
        child: IntrinsicWidth(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              RaisedButton(
                child: Text("hello"),
                onPressed: () {},
              ),
              RaisedButton(
                child: Text("another hello"),
                onPressed: () {},
              ),
              RaisedButton(
                child: Text("DB"),
                onPressed: () {},
              ),
            ],
          ),
        ),
      ),

enter image description here

like image 187
Raouf Rahiche Avatar answered Sep 28 '22 06:09

Raouf Rahiche