Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the width of a RaisedButton in Flutter?

I have seen that I can't set the width of a ElevatedButton in Flutter. If I have well understood, I should put the ElevatedButton into a SizedBox. I will then be able to set the width or height of the box. Is it correct? Is there another way to do it?

This is a bit tedious to create a SizedBox around every buttons so I'm wondering why they have chosen to do it this way. I'm pretty sure that they have a good reason to do so but I don't see it. The scaffolding is pretty difficult to read and to build for a beginner.

new SizedBox(   width: 200.0,   height: 100.0,   child: ElevatedButton(     child: Text('Blabla blablablablablablabla bla bla bla'),     onPressed: _onButtonPressed,   ), ), 
like image 892
OlivierGrenoble Avatar asked May 11 '18 13:05

OlivierGrenoble


People also ask

How do you adjust the full width on a Flutter?

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.


Video Answer


1 Answers

As said in documentation here

Raised buttons have a minimum size of 88.0 by 36.0 which can be overidden with ButtonTheme.

You can do it like that

ButtonTheme(   minWidth: 200.0,   height: 100.0,   child: RaisedButton(     onPressed: () {},     child: Text("test"),   ), ); 
like image 178
Airon Tark Avatar answered Sep 21 '22 11:09

Airon Tark