Make buttons in a row have the same width in flutter

33,825

Solution 1

You can use a Row wrapping your children with Expanded:

Row(
  children: <Widget>[
    Expanded(
      child: RaisedButton(
        child: Text('Approve'),
        onPressed: () => null,
      ),
    ),
    Expanded(
      child: RaisedButton(
        child: Text('Reject'),
        onPressed: () => null,
      ),
    ),
    Expanded(
      child: RaisedButton(
        child: Text('Need Revise'),
        onPressed: () => null,
      ),
    )
  ],
);

Solution 2

There are two ways:

  1. Expanded widget it will divide space in equal parts. If you use all expanded widget for row of column.
  2. Get the width of the screen and divide it into the required sizes equally.

Double width = MediaQuery.of(context).size.width;

Solution 3

can use new Buttons styles:

ElevatedButtonTheme(
      data: ElevatedButtonThemeData(style: ElevatedButton.styleFrom(minimumSize: Size(120,60))) ,
      child: ButtonBar(
        mainAxisSize: MainAxisSize.max,
        children: [
          ElevatedButton(
            child: Text('Ok'),
            onPressed: () {},
          ),
          ElevatedButton(
            child: Text('Cancel'),
            onPressed: () {},
          ),
        ],
      ),
    ),

Although diegoveloper's answer is faster

Share:
33,825
esthrim
Author by

esthrim

Updated on July 09, 2022

Comments

  • esthrim
    esthrim almost 2 years

    If I want to make two or more Buttons in a Row to have the same Width, how do I make it? For examples I have three RaisedButtons with different title let say Approve, Reject and Need Revise and if I put the three Buttons in a Row, they will have different Width and I don't want it. What I need is for they have the same Width.

  • Pawan
    Pawan over 5 years
    Thanks I was using Flexible earlier, but using Expanded instead of Flexible solved y issue. Thanks
  • questionasker
    questionasker almost 5 years
    how about if we want to make same size in a column ?
  • Nihar Dodiya
    Nihar Dodiya over 4 years
    Hii how can i add space between button?
  • pedro_bb7
    pedro_bb7 almost 4 years
    @coderInrRain check this link for your problem. stackoverflow.com/questions/51684730/…
  • Hitesh Surani
    Hitesh Surani almost 4 years
    You're save my day!
  • Kamlesh
    Kamlesh almost 3 years
    I have 7 buttons in a row. A row can have only 2-3 buttons as per available width of mobile. Kindly suggest me how can I wrap multiple buttons in row automatically? Thank you.
  • Kamlesh
    Kamlesh almost 3 years
    I have 7 buttons in a row. A row can have only 2-3 buttons as per available width of mobile. Kindly suggest me how can I wrap multiple buttons in row automatically? Thank you.
  • Firenze
    Firenze over 2 years
    @NiharDodiya You can add space between buttons using SizedBox(width : <double number>),
  • Tommie C.
    Tommie C. over 2 years
    @Kamlesh - If you change the Row into a Wrap widget (in combination with some of the suggestions on this thread), I think you will get the desired effect.
  • JAHelia
    JAHelia about 2 years
    and how to let those buttons have the same height ?