-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
c: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
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;
}),
),
),
);Metadata
Metadata
Assignees
Labels
c: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.