Skip to content

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

@chrisbobbe

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    d: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.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 onr: 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