Closed
Description
Why don't we have IconButtonThemeData
just like ElevatedButtonThemeData or TextButtonThemeData? We do have IconThemeData to provide consistent icon styling across the whole app, but when it comes to styling IconButton, it is a problem. It inherits styling properties from the default values of ThemeData such as focusColor
, disabledColor
and highlightColor
. I don't think it's convenient to build custom icon buttons using Theme Data.
Use case
The most common use case that I can think of is to change the icon color of icon button when it is pressed.
Proposal
There will be IconButtonThemeData
and its style property as ButtonStyle
. The implementation will be similar to the following code:
final ThemeData myTheme = ThemeData(
iconButtonTheme: IconButtonThemeData(
style: ButtonStyle(
// Icon Color
foregroundColor: MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.pressed))
// Make icon color grey when it is pressed
return Colors.grey;
// Default color
return Colors.blue;
}),
// We can also change the icon based on material states
iconData: MaterialStateProperty.resolveWith<IconData>((states) {
if (states.contains(MaterialState.hovered))
// Change icon
return Icons.cancel;
// Default icon
return Icons.add;
}),
),
),
);