-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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
Assignees
Labels
Type
Projects
Status