Repository navigation
Open
Labels
P2Important issues not at the top of the work lista: fidelityMatching the OEM platforms betterp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team
Description
ElevatedButton.styleFrom(elevation: e) derives these elevations (code):
- disabled: 0
- hovered or focused:
e+ 2 - pressed:
e+ 6 - otherwise:
e
These offsets come from the Material 2 elevated button, which is 2 at rest, 4 when hovered or focused, and 8 when pressed. They don't match Material 3 or Material 3 Expressive, where the focused and pressed elevations are the same as the resting one:
| State | Material 3 (defaults) | Material 3 Expressive (tokens) | styleFrom(elevation: 1) |
|---|---|---|---|
| Resting | 1 | 1 | 1 |
| Hovered | 3 | 1 | 3 |
| Focused | 1 | 1 | 3 |
| Pressed | 1 | 1 | 7 |
| Disabled | 0 | 0 | 0 |
So an app that uses styleFrom to set the Material 3 resting elevation gets a button that rises to 7 when it's pressed, while the default button stays at 1.
final WidgetStateProperty<double?> elevation = ElevatedButton.styleFrom(elevation: 1).elevation!;
elevation.resolve(<WidgetState>{WidgetState.pressed}); // 7.0, but 1.0 in Material 3
elevation.resolve(<WidgetState>{WidgetState.focused}); // 3.0, but 1.0 in Material 3styleFrom is static and has no BuildContext, so it can't choose the offsets based on ThemeData.useMaterial3 or ElevatedButtonThemeData.variant. Some options:
- Keep the current behavior. [material_ui] Fix M3 doc errors in the
ElevatedButtonandFilledButtonpackages#13685 documents it, and apps can pass aWidgetStatePropertytoButtonStyle.elevationto set each state. - Match Material 3:
e+ 2 when hovered, andewhen focused or pressed. This changes existing apps that usestyleFrom(elevation: ...), including Material 2 apps. - Use
efor every enabled state, and keep 0 when disabled. This matches Material 3 Expressive and is closer toFilledButton.styleFrom,OutlinedButton.styleFrom, andTextButton.styleFrom, which use one value for all states. It's also a behavior change.
Found while fixing the ElevatedButton docs in flutter/packages#13685.
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work lista: fidelityMatching the OEM platforms betterp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team
Activity
[material_ui] Fix M3 doc errors in the `ElevatedButton` and `FilledBu…