Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Proposal to add IconButtonThemeData #84910

Closed
@afnx

Description

@afnx

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 capabilityc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions