Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make buttons in a row have the same width in flutter

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.

like image 970
esthrim Avatar asked Oct 01 '18 02:10

esthrim


People also ask

How do you give a Row a width in 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.


2 Answers

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,       ),     )   ], ); 
like image 117
diegoveloper Avatar answered Oct 22 '22 06:10

diegoveloper


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;

like image 32
Viren V Varasadiya Avatar answered Oct 22 '22 07:10

Viren V Varasadiya