Reputation: 12182
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,
)
Upvotes: 85
Views: 145816
Reputation: 344
I try above answers but don't work in my case. Here if you use icon button in suffix text field. Flutter v3.27.1
TextField(
decoration: AppTheme.inputDecorationFill.copyWith(
suffixIcon: Container(
height: 0, // <====
width: 0, // <====
padding: EdgeInsets.all(4), // <====
child: IconButton(
onPressed: () {},
padding: EdgeInsets.zero, // <====
icon: Icon(
Icons.visibility_rounded,
),
),
),
),
),
Upvotes: 0
Reputation: 11
if you want to give a square size here is how to do it
IconButton(
padding: const EdgeInsets.all(0),
constraints: BoxConstraints.tight(const Size.square(35)),
onPressed: () {
},
iconSize: 22,
icon: const Icon(LucideIcons.trash),
),
Upvotes: 0
Reputation: 965
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,
)
Upvotes: 29
Reputation: 440
I think there is a better way
.
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: () {},
)
Upvotes: 5
Reputation: 676
You need three things
//
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
),
),
Upvotes: 0
Reputation: 677
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: () {},
);
Upvotes: 7
Reputation: 12182
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,
)
)
Upvotes: 151
Reputation: 619
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,
),
)
Upvotes: 13
Reputation: 426
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.
Upvotes: 4
Reputation: 1833
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,
)
Upvotes: 0
Reputation: 1203
You can replace IconButton with InkWell:
InkWell(
child: Icon(Icons.clear, size: 18.0, color: themeData.primaryColor),
onTap: onDelete,
),
Upvotes: 31
Reputation: 1407
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.
Upvotes: 52