I am trying to create square buttons, but Expanded doesn't seem to work the same as it does with containers. Take the following code for example
new Expanded( flex: 2, child: new Column( children: <Widget>[ new Expanded( child:new Row( children: <Widget>[ new Expanded(child: new MaterialButton(...)), new Expanded(child: new MaterialButton(....)), new Expanded(child: new Container(color: Colors.red)), new Expanded(child: new Container(color: Colors.green)), ] ) ) ], ) ) ....
It displays two buttons that are expanded horizontally, but not vertically. At the same time the containers will expand both horizontally and vertically. The same effect occurs if I do the following:
new Expanded( flex: 2, child: new Column( children: <Widget>[ new Expanded( child:new Column( children: <Widget>[ new Expanded(child: new MaterialButton(...)), new Expanded(child: new MaterialButton(....)), new Expanded(child: new Container(color: Colors.red)), new Expanded(child: new Container(color: Colors.green)), ] ) ) ], ) ) ....
Where I've changed the Row to Column. The buttons will expand vertically, but not horizontally, while the containers will do both.
Is there a way have my buttons expand to fit their parent both vertically and horizontally?
Creating a Full Width Button in Flutter (The Solution)The full width is set to the Elevated Button by adding a style parameter. Then you can use the ElevatedButton. styleFrom class to provide the size of the button using the property called minimumSize.
Add the crossAxisAlignment
property to your Row
;
crossAxisAlignment: CrossAxisAlignment.stretch
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With