Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented Aug 27, 2025

Description

This PR fixes IconButton icon color resolution.

Before

The IconButton.color property does not take precedence over the ambient IconButtonTheme

After

The IconButton.color property overrides the ambient IconButtonTheme.

Related Issue

Fixes SnackBar closeIconColor does not respect widget override
Fixes IconButton.color is overidden by IconButtonTheme

Tests

Adds 1 test.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Aug 27, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes an issue where IconButton.color was being overridden by IconButtonTheme. The change in button_style_button.dart adjusts the color resolution precedence to prioritize the widget's properties over the theme's properties, which aligns with the expected behavior. The new test case in icon_button_test.dart effectively validates this fix. I have one minor suggestion to improve the test's documentation.

@bleroux bleroux force-pushed the fix_icon_button_color_overrided_by_iconTheme branch 2 times, most recently from d0ae22b to acdaac9 Compare August 27, 2025 14:05
@dkwingsmt dkwingsmt requested review from QuncCccccc, dkwingsmt and victorsanni and removed request for dkwingsmt August 27, 2025 18:18
Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the change.

@AlexV525 AlexV525 added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 28, 2025

autosubmit label was removed for flutter/flutter/174515, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2025
@victorsanni
Copy link
Contributor

victorsanni commented Aug 28, 2025

Google testing failures seem legitimate.

@bleroux
Copy link
Contributor Author

bleroux commented Aug 29, 2025

@victorsanni Thanks for the review 🙏
Can you share some details about the Google tests failures?
Are they related to IconButtons only or to other button types? If the later I can probably narrow my fix.

return widgetStyle?.iconColor?.resolve(statesController.value) ??
themeStyle?.iconColor?.resolve(statesController.value) ??
widgetStyle?.foregroundColor?.resolve(statesController.value) ??
themeStyle?.iconColor?.resolve(statesController.value) ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to make widgetStyle.iconColor grab IconButton.color? That should help with the google failures.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of changing the order for resolving these colors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to make widgetStyle.iconColor grab IconButton.color?

Thanks for the suggestion, I updated the PR to restrict the code change to IconButton.
Let see how it goes with Google tests now 🤞

@victorsanni victorsanni self-requested a review August 29, 2025 21:03
@bleroux bleroux force-pushed the fix_icon_button_color_overrided_by_iconTheme branch from 0f22407 to b4ae2c6 Compare September 1, 2025 07:35
Color? focusColor,
Color? hoverColor,
Color? highlightColor,
Color? iconColor,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems will be a duplicate api with foregroundColor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just add documentation for ButtonStyle.iconColor? We can mention this is used for common buttons like Elevated, Filled, FilledTonal, Outlined, and Text buttons. For IconButton, use foregroundColor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean discouraging users from doing the following?

        iconButtonTheme: const IconButtonThemeData(
          style: ButtonStyle(iconColor: WidgetStateColor.fromMap({WidgetState.any: Colors.purple})),
        ),

It seems counterintuitive that iconColor does not apply to the icon color. Documentation will help but it would be more user friendly if iconColor applies to the IconButton icon.
Let me know if we go to the documentation only change or if we try to get the Google tests green.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean discouraging users from doing the following?

No, sorry for the confusion. I mean for IconButton.styleFrom method, we already have a foregroundColor, so I really think it's unnecessary to introduce another one. For ButtonStyle, you are definitely right:)! The icon color should respect ButtonStyle.iconColor.

The priority for these color-related properties are:
IconButton.style -> IconButton.color -> IconButtonTheme.style -> default style

This is my understanding for the issue. When IconButton.color is not null, its value is passed to adjustedStyle.foregroundColor in IconButton, and will merge with IconButton.style. So after the merge, this adjustedStyle will be passed to ButtonStyleButton.widgetStyle. But because in ButtonStyleButton, theme iconColor has higher priority then widget foregroundColor, so the issue happened. This priority order makes sense to common buttons but not for IconButton.

One solution I can think of is: after the merge in IconButton, if adjustedStyle.iconColor is still null, we should copy adjustedStyle.foregroundColor into adjustedStyle.iconColor. Like:

      // This is the original implementation to merge styles
      if (style != null) {
        adjustedStyle = style!.merge(adjustedStyle);
      }
      // Add following
      if (adjustedStyle.iconColor == null) {
        adjustedStyle = adjustedStyle.copyWith(iconColor: adjustedStyle.foregroundColor);
      }

Sorry for the message wall! Currently this PR change will cause a problem, when we add both IconButton.style(foregroundColor: xxx) and IconButton.color, IconButton.style is not respected. Like:

IconButton(
    style: IconButton.styleFrom(foregroundColor: Colors.blue),
    onPressed: () {},
    icon: const Icon(Icons.settings_outlined, size: 64),
    color: Colors.green,
),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the clarification 🙏

I agree with your solution which relies on ButtonStyle.copyWith(iconColor. I did not realized that iconColor was a valid copyWith parameter, I started with IconButton.styleFrom which does not have the iconColor parameter (see #163126) and quickly jump to another way.

@bleroux bleroux force-pushed the fix_icon_button_color_overrided_by_iconTheme branch from b4ae2c6 to 998ad89 Compare September 4, 2025 06:40
Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the fix!

@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 4, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Sep 4, 2025
Merged via the queue into flutter:master with commit c1ce4e5 Sep 4, 2025
78 of 79 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 4, 2025
@bleroux bleroux deleted the fix_icon_button_color_overrided_by_iconTheme branch September 5, 2025 05:35
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Sep 5, 2025
Roll Flutter from 6b18740d5a23 to 87d5b753196c (88 revisions)

flutter/flutter@6b18740...87d5b75

2025-09-05 [email protected] [ Device Lab ] Add regression testing for flutter/flutter#174952 (flutter/flutter#174956)
2025-09-05 [email protected] Roll Skia from 0ca53adfc6cc to 845ec125e94c (2 revisions) (flutter/flutter#174978)
2025-09-05 [email protected] [a11y-app] Fix NavigationRail leading and trailing labels (flutter/flutter#174861)
2025-09-05 [email protected] Roll Skia from d7e99be07d5d to 0ca53adfc6cc (5 revisions) (flutter/flutter#174972)
2025-09-05 [email protected] Roll Fuchsia Linux SDK from izfNA3o_2zL4Cjqmy... to xG_uERsxHvUwFHpF2... (flutter/flutter#174970)
2025-09-04 [email protected] Fix IconButton.color overrided by IconButtomTheme (flutter/flutter#174515)
2025-09-04 [email protected] [web] Reuse chrome instance to run all flutter tests (flutter/flutter#174957)
2025-09-04 [email protected] fix(Semantics): Ensure semantics properties take priority over button's (flutter/flutter#174473)
2025-09-04 [email protected] Make every LLDB Init error message actionable (flutter/flutter#174726)
2025-09-04 [email protected] Fix table cell semantics rect alignment issues.  (flutter/flutter#174914)
2025-09-04 [email protected] Fix: Use route navigator for CupertinoSheetRoute pop (flutter/flutter#173103)
2025-09-04 [email protected] [ Widget Preview] Add `group` property to `Preview` (flutter/flutter#174849)
2025-09-04 [email protected] Allow OverlayPortal.overlayChildLayoutBuilder to choose root Overlay (flutter/flutter#174239)
2025-09-04 [email protected] Roll Skia from 7c2f502e3304 to d7e99be07d5d (18 revisions) (flutter/flutter#174936)
2025-09-04 [email protected] Remove 'terms of use' wording from web_unicode (flutter/flutter#174939)
2025-09-04 [email protected] [ Tool ] Remove leftover Android x86 deprecation warning constant (flutter/flutter#174941)
2025-09-04 [email protected] Prevent potential crash when accessing window in FlutterSceneDelegate (flutter/flutter#174873)
2025-09-04 [email protected] Roll Packages from 42bb347 to 98580c6 (5 revisions) (flutter/flutter#174943)
2025-09-04 [email protected] [ Device Lab ] Fix wakefulness check to only match log entries with string values (flutter/flutter#174953)
2025-09-04 [email protected] Fix expanded DropdownMenu panel is shorter than text field (flutter/flutter#174443)
2025-09-04 [email protected] Add a `viewController` property to the ios/macOS `FlutterPluginRegistrar` protocol  (flutter/flutter#174168)
2025-09-03 [email protected] Roll Fuchsia Linux SDK from J3T_wZqL_57mRfWky... to izfNA3o_2zL4Cjqmy... (flutter/flutter#174908)
2025-09-03 [email protected] Wires up Android API to set section locale (flutter/flutter#173364)
2025-09-03 [email protected] Delete impeller::SPrintF. (flutter/flutter#174900)
2025-09-03 [email protected] Make sure that a DropdownMenuFormField doesn't crash in 0x0 environment (flutter/flutter#174777)
2025-09-03 [email protected] Remove unnecessary `presubmit_max_attempts` from .ci.yaml (flutter/flutter#174885)
2025-09-03 [email protected] Use local canvaskit in `dart_data_asset_test.dart` (flutter/flutter#174891)
2025-09-03 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Mark Linux web_canvaskit_tests_7_last as bringup (#174878)" (flutter/flutter#174897)
2025-09-03 [email protected] Correct intrinsics calculation for CupertinoTextField with placeholder (flutter/flutter#174889)
2025-09-03 [email protected] Considers large title height in CupertinoNavigationBar's preferred size (flutter/flutter#173722)
2025-09-03 [email protected] [A11y] Add semantics for CupertinoExpansionTile (flutter/flutter#174480)
2025-09-03 [email protected] Fix LinearProgressIndicator track painting. (flutter/flutter#173108)
2025-09-03 [email protected] update triage documentation to include team-android (flutter/flutter#174850)
2025-09-03 [email protected] Update `test_timeout_secs` to match `timeout` for `Linux web_skwasm_tests_*` and `Linux web_canvaskit_tests_*` (flutter/flutter#174881)
2025-09-03 [email protected] Roll Packages from 5d785a0 to 42bb347 (10 revisions) (flutter/flutter#174876)
2025-09-03 [email protected] Fixup formatting of gn files in the old buildroot. (flutter/flutter#174852)
2025-09-03 [email protected] Roll Dart SDK to 3.10.0-162.1.beta (flutter/flutter#174834)
2025-09-03 [email protected] Mark Linux web_canvaskit_tests_7_last as bringup (flutter/flutter#174878)
2025-09-02 [email protected] [Impeller] Fix overdraw in DrawRect geometry (flutter/flutter#174735)
2025-09-02 [email protected] Patch .clang-format files to specify C++20. (flutter/flutter#174848)
2025-09-02 [email protected] Add data assets (flutter/flutter#174685)
2025-09-02 [email protected] refactors `FlutterPlugin.kt` to use one line statement in the `into` bloc (flutter/flutter#174759)
2025-09-02 [email protected] Ensures initial semantics state is sent to engine (flutter/flutter#174845)
2025-09-02 [email protected] [Android] Break up plugin_test integration tests (flutter/flutter#174728)
2025-09-02 [email protected] Fix: Assertion failure in RawScrollbarState with dynamic controller assignment (flutter/flutter#173156)
2025-09-02 [email protected] Roll Skia from 359f3d7cc7ed to 7c2f502e3304 (1 revision) (flutter/flutter#174844)
...
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
## Description

This PR fixes IconButton icon color resolution. 

## Before

The IconButton.color property does not take precedence over the ambient
`IconButtonTheme`

## After

The IconButton.color property overrides the ambient `IconButtonTheme`.

## Related Issue

Fixes [SnackBar closeIconColor does not respect widget
override](flutter#174472)
Fixes [IconButton.color is overidden by
IconButtonTheme](flutter#174511)

## Tests

Adds 1 test.
Jaineel-Mamtora pushed a commit to Jaineel-Mamtora/flutter_forked that referenced this pull request Sep 24, 2025
## Description

This PR fixes IconButton icon color resolution. 

## Before

The IconButton.color property does not take precedence over the ambient
`IconButtonTheme`

## After

The IconButton.color property overrides the ambient `IconButtonTheme`.

## Related Issue

Fixes [SnackBar closeIconColor does not respect widget
override](flutter#174472)
Fixes [IconButton.color is overidden by
IconButtonTheme](flutter#174511)

## Tests

Adds 1 test.
danferreira pushed a commit to danferreira/packages that referenced this pull request Oct 22, 2025
…r#9962)

Roll Flutter from 6b18740d5a23 to 87d5b753196c (88 revisions)

flutter/flutter@6b18740...87d5b75

2025-09-05 [email protected] [ Device Lab ] Add regression testing for flutter/flutter#174952 (flutter/flutter#174956)
2025-09-05 [email protected] Roll Skia from 0ca53adfc6cc to 845ec125e94c (2 revisions) (flutter/flutter#174978)
2025-09-05 [email protected] [a11y-app] Fix NavigationRail leading and trailing labels (flutter/flutter#174861)
2025-09-05 [email protected] Roll Skia from d7e99be07d5d to 0ca53adfc6cc (5 revisions) (flutter/flutter#174972)
2025-09-05 [email protected] Roll Fuchsia Linux SDK from izfNA3o_2zL4Cjqmy... to xG_uERsxHvUwFHpF2... (flutter/flutter#174970)
2025-09-04 [email protected] Fix IconButton.color overrided by IconButtomTheme (flutter/flutter#174515)
2025-09-04 [email protected] [web] Reuse chrome instance to run all flutter tests (flutter/flutter#174957)
2025-09-04 [email protected] fix(Semantics): Ensure semantics properties take priority over button's (flutter/flutter#174473)
2025-09-04 [email protected] Make every LLDB Init error message actionable (flutter/flutter#174726)
2025-09-04 [email protected] Fix table cell semantics rect alignment issues.  (flutter/flutter#174914)
2025-09-04 [email protected] Fix: Use route navigator for CupertinoSheetRoute pop (flutter/flutter#173103)
2025-09-04 [email protected] [ Widget Preview] Add `group` property to `Preview` (flutter/flutter#174849)
2025-09-04 [email protected] Allow OverlayPortal.overlayChildLayoutBuilder to choose root Overlay (flutter/flutter#174239)
2025-09-04 [email protected] Roll Skia from 7c2f502e3304 to d7e99be07d5d (18 revisions) (flutter/flutter#174936)
2025-09-04 [email protected] Remove 'terms of use' wording from web_unicode (flutter/flutter#174939)
2025-09-04 [email protected] [ Tool ] Remove leftover Android x86 deprecation warning constant (flutter/flutter#174941)
2025-09-04 [email protected] Prevent potential crash when accessing window in FlutterSceneDelegate (flutter/flutter#174873)
2025-09-04 [email protected] Roll Packages from 42bb347 to 98580c6 (5 revisions) (flutter/flutter#174943)
2025-09-04 [email protected] [ Device Lab ] Fix wakefulness check to only match log entries with string values (flutter/flutter#174953)
2025-09-04 [email protected] Fix expanded DropdownMenu panel is shorter than text field (flutter/flutter#174443)
2025-09-04 [email protected] Add a `viewController` property to the ios/macOS `FlutterPluginRegistrar` protocol  (flutter/flutter#174168)
2025-09-03 [email protected] Roll Fuchsia Linux SDK from J3T_wZqL_57mRfWky... to izfNA3o_2zL4Cjqmy... (flutter/flutter#174908)
2025-09-03 [email protected] Wires up Android API to set section locale (flutter/flutter#173364)
2025-09-03 [email protected] Delete impeller::SPrintF. (flutter/flutter#174900)
2025-09-03 [email protected] Make sure that a DropdownMenuFormField doesn't crash in 0x0 environment (flutter/flutter#174777)
2025-09-03 [email protected] Remove unnecessary `presubmit_max_attempts` from .ci.yaml (flutter/flutter#174885)
2025-09-03 [email protected] Use local canvaskit in `dart_data_asset_test.dart` (flutter/flutter#174891)
2025-09-03 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Mark Linux web_canvaskit_tests_7_last as bringup (#174878)" (flutter/flutter#174897)
2025-09-03 [email protected] Correct intrinsics calculation for CupertinoTextField with placeholder (flutter/flutter#174889)
2025-09-03 [email protected] Considers large title height in CupertinoNavigationBar's preferred size (flutter/flutter#173722)
2025-09-03 [email protected] [A11y] Add semantics for CupertinoExpansionTile (flutter/flutter#174480)
2025-09-03 [email protected] Fix LinearProgressIndicator track painting. (flutter/flutter#173108)
2025-09-03 [email protected] update triage documentation to include team-android (flutter/flutter#174850)
2025-09-03 [email protected] Update `test_timeout_secs` to match `timeout` for `Linux web_skwasm_tests_*` and `Linux web_canvaskit_tests_*` (flutter/flutter#174881)
2025-09-03 [email protected] Roll Packages from 5d785a0 to 42bb347 (10 revisions) (flutter/flutter#174876)
2025-09-03 [email protected] Fixup formatting of gn files in the old buildroot. (flutter/flutter#174852)
2025-09-03 [email protected] Roll Dart SDK to 3.10.0-162.1.beta (flutter/flutter#174834)
2025-09-03 [email protected] Mark Linux web_canvaskit_tests_7_last as bringup (flutter/flutter#174878)
2025-09-02 [email protected] [Impeller] Fix overdraw in DrawRect geometry (flutter/flutter#174735)
2025-09-02 [email protected] Patch .clang-format files to specify C++20. (flutter/flutter#174848)
2025-09-02 [email protected] Add data assets (flutter/flutter#174685)
2025-09-02 [email protected] refactors `FlutterPlugin.kt` to use one line statement in the `into` bloc (flutter/flutter#174759)
2025-09-02 [email protected] Ensures initial semantics state is sent to engine (flutter/flutter#174845)
2025-09-02 [email protected] [Android] Break up plugin_test integration tests (flutter/flutter#174728)
2025-09-02 [email protected] Fix: Assertion failure in RawScrollbarState with dynamic controller assignment (flutter/flutter#173156)
2025-09-02 [email protected] Roll Skia from 359f3d7cc7ed to 7c2f502e3304 (1 revision) (flutter/flutter#174844)
...
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
## Description

This PR fixes IconButton icon color resolution. 

## Before

The IconButton.color property does not take precedence over the ambient
`IconButtonTheme`

## After

The IconButton.color property overrides the ambient `IconButtonTheme`.

## Related Issue

Fixes [SnackBar closeIconColor does not respect widget
override](flutter#174472)
Fixes [IconButton.color is overidden by
IconButtonTheme](flutter#174511)

## Tests

Adds 1 test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IconButton.color is overidden by IconButtonTheme SnackBar closeIconColor does not respect widget override

4 participants