Skip to content

Create widgets level support for States, StateProperties #138270

@Piinks

Description

@Piinks

MaterialStateProperties are really useful for styling components based on their current state
For example, if we consider a button's background color, instead of enumerating all of the possible state combinations that could result in a color...

  • disabled
  • enabled
  • hovered
  • selected
  • disabledAndHovered
  • enabledAndHovered
  • enabledAndHoveredAndSelected
  • ETC, AND SO ON...

You can provide a color based on the current list of states provided to the MaterialStateProperty, so you have evaluate and provide the desired color. For example:

final myColor = MaterialStateProperty.resolveWith<Color?>(
      (Set<MaterialState> states) {
        if (states.contains(MaterialState.pressed) ||
            states.contains(MaterialState.hovered)) {
          return $styles.colors.summer;
        }
        return $styles.colors.white;
      },
    );

This is great, but does not help when developers are building in the widgets library. We should see about moving this concept into the scope of all widgets.

Ideally, we would do this in a non-breaking fashion (preserving MaterialStateProperties), but hopefully in a way that allows the material and non-material versions to be used interchangeably.

Metadata

Metadata

Labels

Design Systems StudyIssues identified during the custom design system study.P2Important issues not at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions