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:
- Expanded widget it will divide space in equal parts. If you use all expanded widget for row of column.
- 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
Author by
esthrim
Updated on July 09, 2022Comments
-
esthrim almost 2 years
If I want to make two or more
Buttons
in aRow
to have the sameWidth
, how do I make it? For examples I have threeRaisedButtons
with different title let sayApprove
,Reject
andNeed Revise
and if I put the threeButton
s in aRow
, they will have differentWidth
and I don't want it. What I need is for they have the sameWidth
. -
Pawan over 5 yearsThanks I was using Flexible earlier, but using Expanded instead of Flexible solved y issue. Thanks
-
questionasker almost 5 yearshow about if we want to make same size in a column ?
-
Nihar Dodiya over 4 yearsHii how can i add space between button?
-
pedro_bb7 almost 4 years@coderInrRain check this link for your problem. stackoverflow.com/questions/51684730/…
-
Hitesh Surani almost 4 yearsYou're save my day!
-
Kamlesh almost 3 yearsI 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 almost 3 yearsI 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 over 2 years@NiharDodiya You can add space between buttons using SizedBox(width : <double number>),
-
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 about 2 yearsand how to let those buttons have the same height ?