Skip to content

IconButton.styleFrom is missing iconColor property #163126

Closed as not planned
Closed as not planned

Description

@TahaTesser

Steps to reproduce

More details in this thread.
#162880 (comment)

This works as expected

Image

Image

However, we can't define iconColor in the button style class using IconButton.styleFrom. IconButton.styleFrom is missing iconColor property.
https://api.flutter.dev/flutter/material/IconButton/styleFrom.html

Expected results

IconButton icon color should be customizable using ButtonStyle.iconColor as well as using IconButton.styleFrom

IconButton.styleFrom is missing iconColor property
https://api.flutter.dev/flutter/material/IconButton/styleFrom.html

Actual results

Cannot override iconColor using IconButton.styleFrom.

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(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: IconButtonTheme(
            data: const IconButtonThemeData(
              style: ButtonStyle(
                iconColor: WidgetStatePropertyAll<Color>(Colors.red),
              ),
              // ),
              // data: IconButton.styleFrom(
              //   iconColor:
            ),
            child: IconButton(
              onPressed: () {},
              icon: const Icon(Icons.ac_unit),
            ),
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]

Activity

  1. self-assigned this
    on Feb 12, 2025
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    team-designOwned by Design Languages team
    on Feb 12, 2025
  3. changed the title [-]`IconButton` only supports `ButtonStyle.iconColor` since `IconButton.styleFrom` doesn't have the `iconColor property[/-] [+]`IconButton` only supports `ButtonStyle.iconColor` since `IconButton.styleFrom` doesn't have the `iconColor` property[/+] on Feb 12, 2025
  4. changed the title [-]`IconButton` only supports `ButtonStyle.iconColor` since `IconButton.styleFrom` doesn't have the `iconColor` property[/-] [+]`IconButton.styleFrom` is missing `iconColor property[/+] on Feb 12, 2025
  5. changed the title [-]`IconButton.styleFrom` is missing `iconColor property[/-] [+]`IconButton.styleFrom` is missing `iconColor` property[/+] on Feb 12, 2025
  6. TahaTesser commented on Feb 12, 2025

    @TahaTesser
    ContributorAuthor

    Is it worth adding iconColor to IconButton.styleFrom or should we ignore it for IconButton as it'd typically only have icon? @rydmike @QuncCccccc

  7. rydmike commented on Feb 12, 2025

    @rydmike
    Contributor

    As long as the icon gets the correct color when using IconButton.styleFrom.foregroundColor that is fine imo. No need to pollute and confuse this convenience API with an extra iconColor when there is only one part to color in the IconButton, especially since foreground color already also has the disabledForegroundColor helper.

    I was just concerned about what the behavior is when you use raw ButtonStyle on an IconButton and provide just foregroundColor or iconColor, or both, that all three cases work and that it also then has the right fallback priority via foregroundColor and then iconColor.

    Sounds and looks like that part is covered and works OK.

  8. TahaTesser commented on Feb 12, 2025

    @TahaTesser
    ContributorAuthor

    Sounds good to me!

  9. moved this from To do to Done (PR merged) in Nevercodeon Feb 12, 2025
  10. removed their assignment
    on Feb 12, 2025
  11. github-actions commented on Feb 26, 2025

    @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.

  12. locked as resolved and limited conversation to collaborators on Feb 26, 2025
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

    frameworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesteam-designOwned by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions