Skip to content

M3 Button MaterialStateProperty defaults don't resolve MaterialState.pressed #122250

@HansMuller

Description

@HansMuller

Many of the MaterialStateProperty defaults for the Button classes are defined like the example from ElevatedButton below. The MaterialState.pressed and MaterialState.hovered states are always reported together, so the resolved color is always the hovered one, since that clause is first. The order should be pressed then hovered, since hovered can occur without pressed.

  MaterialStateProperty<Color?>? get overlayColor =>
    MaterialStateProperty.resolveWith((Set<MaterialState> states) {
      if (states.contains(MaterialState.hovered)) {
        return _colors.primary.withOpacity(0.08);
      }
      if (states.contains(MaterialState.focused)) {
        return _colors.primary.withOpacity(0.12);
      }
      if (states.contains(MaterialState.pressed)) {
        return _colors.primary.withOpacity(0.12);
      }
      return null;
    });

Metadata

Metadata

Assignees

Labels

f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions