Skip to content

Expose foreground property of TextStyle in Icon widget #139411

@evan361425

Description

@evan361425

Is there an existing issue for this?

Use case

I would like to make my icon's color change when background color changes. I realized that it can achieve by BlendMode.different from my own SO question.

I can do this in my local test with below code:

final style = TextStyle(
  foreground: Paint()
    ..blendMode = BlendMode.difference
    ..color = Colors.white,
  // other properties
);

TextSpan(text: String.fromCharCode(icon.codePoint), style: style);
Screen.Recording.2023-12-02.at.11.05.01.AM.mov

Proposal

Expose the foreground property of TextStyle in Icon so that we can use it!

class Icon extends StatelessWidget {
  const Icon(
      this.icon, {
      this.foreground,
      // other properties
  })

  Widget build(context) {
    // ...
    TextStyle(
      forground: forground,
      // ...
    )
  }
}

Also tested on IconButton:

Screen.Recording.2023-12-02.at.11.23.02.AM.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterframeworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions