Skip to content

ButtonStyle: foregroundColor no longer controls icon color, contradicting dartdocs #154644

Closed

Description

@chrisbobbe

Steps to reproduce

  1. Make a FilledButton.icon with an icon and a label, and style: const ButtonStyle(foregroundColor: WidgetStatePropertyAll(Colors.orange)).
  2. See the color of the icon and the label.
  3. Read the dartdocs on ButtonStyle.foregroundColor and ButtonStyle.iconColor:
  /// The color for the button's [Text] and [Icon] widget descendants.
  ///
  /// This color is typically used instead of the color of the [textStyle]. All
  /// of the components that compute defaults from [ButtonStyle] values
  /// compute a default [foregroundColor] and use that instead of the
  /// [textStyle]'s color.
  final MaterialStateProperty<Color?>? foregroundColor;
  /// The icon's color inside of the button.
  ///
  /// If this is null, the icon color will be [foregroundColor].
  final MaterialStateProperty<Color?>? iconColor;

Expected results

The icon and the label should be orange. Or, those dartdocs should not say that ButtonStyle.foregroundColor controls the icon color when iconColor is null.

Actual results

The label is orange, but the icon is not.

The reason: starting with 51ed348 (from #143501), the behavior for iconColor: null is to color the icon with a hard-coded default, instead of using foregroundColor.

See before/after this change in screenshots below.

At the same time, the quoted dartdocs still say that ButtonStyle.foregroundColor controls the icon color when iconColor is null.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Center(
        child: FilledButton.icon(onPressed: () {},
          style: const ButtonStyle(foregroundColor: WidgetStatePropertyAll(Colors.orange)),
          label: const Text('Icon button'),
          icon: const Icon(Icons.save))));
  }
}

Screenshots or Video

Screenshots / Video demonstration
Before (51ed348^) After (51ed348)
image image

Logs

Logs

No unusual log output expected or observed.

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel [user-branch], 3.24.0-1.0.pre.428, on macOS 14.6.1 23G93 darwin-arm64, locale en-US)
    ! Flutter version 3.24.0-1.0.pre.428 on channel [user-branch] at /Users/chrisbobbe/.local/lib/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/setup.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.92.2)
[✓] Connected device (5 available)
[✓] Network resources

! Doctor found issues in 1 category.

Activity

  1. chrisbobbe commented on Sep 4, 2024

    @chrisbobbe
    ContributorAuthor

    I'm not sure whether it's better to change the behavior or update the doc. Updating the doc seems easier, at least, so I plan to go ahead and open a PR for that.

    cc @gspencergoog @HansMuller @QuncCccccc as author/reviewers of #143501.

  2. gspencergoog commented on Sep 4, 2024

    @gspencergoog
    Contributor

    I'm not sure whether it's better to change the behavior or update the doc. Updating the doc seems easier, at least, so I plan to go ahead and open a PR for that.

    Yes, updating the doc is the right thing. The Material tokens specify them separately, so they should be independent.

  3. chrisbobbe commented on Sep 4, 2024

    @chrisbobbe
    ContributorAuthor

    Thanks for the prompt reply! Just sent #154646 for this.

  4. darshankawar commented on Sep 5, 2024

    @darshankawar
    Member

    Thanks for the report and potential fix @chrisbobbe
    Verified that this seems to occuring in master version only, as, on latest stable, it works as expected.

    Master version: 3.25.0-1.0.pre.269

  5. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    d: api docsIssues with https://api.flutter.dev/
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Sep 5, 2024
  6. gspencergoog commented on Sep 5, 2024

    @gspencergoog
    Contributor

    Verified that this seems to occuring in master version only, as, on latest stable, it works as expected.

    Actually, they're both working as expected: #143501 was intended to change behavior.

  7. added a commit that references this issue on Sep 6, 2024
    84757af
  8. added
    r: fixedIssue is closed as already fixed in a newer version
    on Sep 9, 2024
  9. github-actions commented on Sep 23, 2024

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  10. locked as resolved and limited conversation to collaborators on Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    d: api docsIssues with https://api.flutter.dev/found in release: 3.25Found to occur in 3.25frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamwaiting for PR to land (fixed)A fix is in flight

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions