80

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,
)

10 Answers 10

145

You can force it to size itself with the SizedBox.

SizedBox(
   height: 18.0,
   width: 18.0,
   child: IconButton(
      padding: EdgeInsets.all(0.0),
      color: themeData.primaryColor,
      icon: Icon(Icons.clear, size: 18.0),
      onPressed: onDelete,
   )
)
1
  • 2
    Does this make the icon thicker or does it just increase the area of the IconButton itself? The one annoying thing about IconButton is that you can't remove the default padding.
    – Michael T
    Commented Sep 7, 2020 at 8:43
52

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.

5
  • 36
    iconSize property changes only the Icon size itself, but not it's container (which is actually a SizedBox) So I assume the only way is to change the button size is to provide your own SizedBox wrapper, as the accepted answer suggests Commented Jul 13, 2019 at 16:45
  • 16
    This is incorrect. It does not change the size of the button, only the icon. Commented May 5, 2020 at 3:17
  • It changes the size of the button if you add it to the IconButton. I was changing the size of the Icon itself which meant much of the icon fell outside of the iconButton. Ensuring you put iconSize on the iconButton fixes this problem
    – Tom
    Commented Jun 10, 2020 at 12:58
  • 5
    Are people reading this wrong? This is obviously the most correct way to do it. People saying it's incorrect must be using the size attribute of the Icon, not the iconSize attribute of the IconButton. Commented Oct 8, 2020 at 22:18
  • 1
    its better than using sizebox Commented Nov 19, 2021 at 14:43
29

You can replace IconButton with InkWell:

InkWell(
    child: Icon(Icons.clear, size: 18.0, color: themeData.primaryColor),
    onTap: onDelete,
),
29

Use the constraints property on IconButton and padding to zero:

IconButton(
    constraints: BoxConstraints(maxHeight: 36),
    icon: new Icon(Icons.clear, size: 18.0),
    padding: EdgeInsets.zero,
)

Source

12

If anyone's looking to change the Splash/Hover shadow size for the icon buttons. You need to set splashRadius property to the desired value in the IconButton.

IconButton(
     splashRadius: 12,
     padding: EdgeInsets.zero,
     icon: Icon(
             Icons.visibility,
              color: Theme.of(context).primaryColorDark,
    ),
)
6

Use IconButton > splashRadius,

IconButton(
  // use this to decrease/increase the splash spacing
  splashRadius: 24.0,  // (Material.defaultSplashRadius = 35.0)
  color: buttonColor,
  icon: Icon(Icons.heart),
  onPressed: () {},
);

demo iconbutton

1
  • 1
    Very underappreciated answer! Commented Aug 21, 2022 at 23:37
4

IconButton's hit region is the area that can perceive user interaction, it has the smallest size is kMinInteractiveDimension (48.0) regardless of the actual size of the Icon.

1
  • This is part of the material guidelines which are not rules but rather good ux recommendations Commented Feb 25 at 20:10
2

I think there is a better way

  1. Set the style -> tapTargetSize: MaterialTapTargetSize.shrinkWrap
  2. Set the desired size with constraints
  3. Adjust the padding

.

IconButton(
  // To make the button size adjust to the icon or the desired size.
  // Without this it will still use its default size.
  style: const ButtonStyle(
    tapTargetSize: MaterialTapTargetSize.shrinkWrap,
  ),
  // Set the desired size
  constraints: BoxConstraints(
    maxWidth: 30,
    minWidth: 30,
    maxHeight: 30,
    minHeight: 30,
  ),
  // Don't forget the padding
  padding: EdgeInsets.zero,
  icon: Icon(Icons.remove),
  iconSize: Sizes.height22,
  onPressed: () {},
)
0

If you use images from assets folder, below should work:

IconButton(
      icon: Image.asset(
        "assets/images/play_3x.png",
        height: 100,
        width: 100,
        color: Colors.white,
)
0

You need three things

  1. set padding to 0
  2. set the size you want for the icon button using the constraints property
  3. control your icon size inside IconButton using the size property in Icon

//

IconButton(
        onPressed: () {},
        padding: EdgeInsets.zero, //1
        constraints: BoxConstraints(maxHeight: 24.0, maxWidth: 24.0), //2
        icon: Icon(
          Icons.keyboard_arrow_down_rounded,
          size: 18.0, //3
        ),
      ),

Not the answer you're looking for? Browse other questions tagged or ask your own question.