IconButton class Null safety

A material design icon button.

An icon button is a picture printed on a Material widget that reacts to touches by filling with color (ink).

Icon buttons are commonly used in the AppBar.actions field, but they can be used in many other places as well.

If the onPressed callback is null, then the button will be disabled and will not react to touch.

Requires one of its ancestors to be a Material widget.

The hit region of an icon button will, if possible, be at least kMinInteractiveDimension pixels in size, regardless of the actual iconSize, to satisfy the touch target size requirements in the Material Design specification. The alignment controls how the icon itself is positioned within the hit region.

This sample shows an IconButton that uses the Material icon "volume_up" to increase the volume.

To create a local project with this code sample, run:
flutter create --sample=material.IconButton.1 mysample

Icon sizes

When creating an icon button with an Icon, do not override the icon's size with its Icon.size parameter, use the icon button's iconSize parameter instead. For example do this:

IconButton(iconSize: 72, icon: Icon(Icons.favorite), ...)

Avoid doing this:

IconButton(icon: Icon(Icons.favorite, size: 72), ...)

If you do, the button's size will be based on the default icon size, not 72, which may produce unexpected layouts and clipping issues.

Adding a filled background

Icon buttons don't support specifying a background color or other background decoration because typically the icon is just displayed on top of the parent widget's background. Icon buttons that appear in AppBar.actions are an example of this.

It's easy enough to create an icon button with a filled background using the Ink widget. The Ink widget renders a decoration on the underlying Material along with the splash and highlight InkResponse contributed by descendant widgets.

In this sample the icon button's background color is defined with an Ink widget whose child is an IconButton. The icon button's filled background is a light shade of blue, it's a filled circle, and it's as big as the button is.

To create a local project with this code sample, run:
flutter create --sample=material.IconButton.2 mysample

See also:



IconButton({Key? key, double? iconSize, VisualDensity? visualDensity, EdgeInsetsGeometry padding = const EdgeInsets.all(8.0), AlignmentGeometry alignment = Alignment.center, double? splashRadius, Color? color, Color? focusColor, Color? hoverColor, Color? highlightColor, Color? splashColor, Color? disabledColor, required VoidCallback? onPressed, MouseCursor? mouseCursor, FocusNode? focusNode, bool autofocus = false, String? tooltip, bool enableFeedback = true, BoxConstraints? constraints, required Widget icon})
Creates an icon button. [...]


alignment AlignmentGeometry
Defines how the icon is positioned within the IconButton. [...]
autofocus bool
True if this widget will be selected as the initial focus when no other node in its scope is currently focused. [...]
color Color?
The color to use for the icon inside the button, if the icon is enabled. Defaults to leaving this up to the icon widget. [...]
constraints BoxConstraints?
Optional size constraints for the button. [...]
disabledColor Color?
The color to use for the icon inside the button, if the icon is disabled. Defaults to the ThemeData.disabledColor of the current Theme. [...]
enableFeedback bool
Whether detected gestures should provide acoustic and/or haptic feedback. [...]
focusColor Color?
The color for the button's icon when it has the input focus. [...]
focusNode FocusNode?
An optional focus node to use as the focus node for this widget. [...]
hashCode int
The hash code for this object. [...]
@nonVirtual, read-only, inherited
highlightColor Color?
The secondary color of the button when the button is in the down (pressed) state. The highlight color is represented as a solid color that is overlaid over the button color (if any). If the highlight color has transparency, the button color will show through. The highlight fades in quickly as the button is held down. [...]
hoverColor Color?
The color for the button's icon when a pointer is hovering over it. [...]
icon Widget
The icon to display inside the button. [...]
iconSize double?
The size of the icon inside the button. [...]
key Key?
Controls how one widget replaces another widget in the tree. [...]
final, inherited
mouseCursor MouseCursor?
The cursor for a mouse pointer when it enters or is hovering over the button. [...]
onPressed VoidCallback?
The callback that is called when the button is tapped or otherwise activated. [...]
padding EdgeInsetsGeometry
The padding around the button's icon. The entire padded icon will react to input gestures. [...]
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
splashColor Color?
The primary color of the button when the button is in the down (pressed) state. The splash is represented as a circular overlay that appears above the highlightColor overlay. The splash overlay has a center point that matches the hit point of the user touch event. The splash overlay will expand to fill the button area if the touch is held for long enough time. If the splash color has transparency then the highlight and button color will show through. [...]
splashRadius double?
The splash radius. [...]
tooltip String?
Text that describes the action that will occur when the button is pressed. [...]
visualDensity VisualDensity?
Defines how compact the icon button's layout will be. [...]


build(BuildContext context) Widget
Describes the part of the user interface represented by this widget. [...]
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree. [...]
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object. [...]
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants. [...]
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object. [...]
toStringShort() String
A short, textual description of this widget.


operator ==(Object other) bool
The equality operator. [...]
@nonVirtual, inherited