Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize (height and width) of an IconButton in Flutter

Tags:

flutter

How to resize (height and width) of an IconButton in Flutter? Seems like it takes a default width and height. There is not height or width property.

new IconButton(
    padding: new EdgeInsets.all(0.0),
    color: themeData.primaryColor,
    icon: new Icon(Icons.clear, size: 18.0),
    onPressed: onDelete,
)
like image 968
Stephane Avatar asked Mar 10 '18 15:03

Stephane


People also ask

How do you change the width of a RaisedButton in flutter?

Raised buttons have a minimum size of 88.0 by 36.0 which can be overridden with ButtonTheme. So you can do it like the following: ButtonTheme( minWidth: 200.0, height: 100.0, child: RaisedButton( onPressed: () {}, child: Text("test"), ), );

How do I add an IconButton in flutter?

The simplest way to create a button with icon and text in Flutter is to use the new Material button called ElevatedButton with an icon constructor. ElevatedButton. icon() gives you the ability to add the icon and label parameter to the button. The ElevatedButton was introduced with the release of Flutter v1.


3 Answers

You can force it to size itself with the SizedBox.

new SizedBox(
   height: 18.0,
   width: 18.0,
   child: new IconButton(
      padding: new EdgeInsets.all(0.0),
      color: themeData.primaryColor,
      icon: new Icon(Icons.clear, size: 18.0),
      onPressed: onDelete,
   )
)
like image 93
Stephane Avatar answered Oct 22 '22 13:10

Stephane


There is a newer way than the accepted answer. It looks like this:

IconButton(
  iconSize: 18.0,
  icon: new Icon(Icons.clear)

So use iconSize attribute and get rid of the SizedBox.

I noticed the old accepted solution had a bad drawing effect when pressing the button.

like image 28
adrianvintu Avatar answered Oct 22 '22 13:10

adrianvintu


You can replace IconButton with InkWell:

InkWell(
    child: Icon(Icons.clear, size: 18.0, color: themeData.primaryColor),
    onTap: onDelete,
),
like image 31
dfmiller Avatar answered Oct 22 '22 14:10

dfmiller