[material_ui] Add Material 3 Expressive IconButton - #12093
Conversation
d2adfa2 to
4b56b94
Compare
41d31eb to
08739af
Compare
2d53a40 to
7585c20
Compare
83f10c1 to
bb4e01b
Compare
bb4e01b to
ca7c3e4
Compare
|
This PR is still trying to merge into |
| /// * `textStyle` - null | ||
| /// * `backgroundColor` - transparent | ||
| /// * `foregroundColor` | ||
| /// * disabled - Theme.colorScheme.onSurface(0.38) |
There was a problem hiding this comment.
What happens if the Material specs are updated? It seems possible that this documentation could get out of date
There was a problem hiding this comment.
Yes, they will change the number but not super frequent. I usually just keep an eye on the new email from material-token-announce to see whether any changes that have been made and we need to pay attention.
Maybe later we can use agent to do regular check on the accuracy of documentation? Just brainstorm haha.
| import '../templates/app_bar_template.dart'; | ||
| import '../templates/banner_template.dart'; | ||
| import '../templates/badge_template.dart'; | ||
| import '../templates/banner_template.dart'; |
There was a problem hiding this comment.
Code Review
This pull request introduces Material 3 Expressive button style variants (ButtonSizeVariant, IconButtonWidthVariant, and ButtonShapeVariant) to ButtonStyle, integrating them into IconButton and IconButtonThemeData. It also adds generated defaults for Material 3 Expressive icon buttons and corresponding tests. The review feedback highlights an inverted shape mapping in the template where square shapes resolve to round borders when selected, and recommends replacing deprecated MaterialStatePropertyAll usages with WidgetStatePropertyAll to align with the modern WidgetState API.
| String get _selectedShapeSwitch { | ||
| return ''' | ||
| switch (shapeVariant) { | ||
| ButtonShapeVariant.round => $_selectedRoundShapeSwitch, | ||
| ButtonShapeVariant.square => $_selectedSquareShapeSwitch, | ||
| }'''; | ||
| } |
There was a problem hiding this comment.
The mapping for selected shapes is inverted. When shapeVariant is square and the button is selected, it resolves to StadiumBorder (fully round), whereas when shapeVariant is round and selected, it resolves to RoundedRectangleBorder (more square). A square button morphing into a fully round StadiumBorder when selected is incorrect. The token mapping or the token database values for selectedContainerShapeRound and selectedContainerShapeSquare should be corrected so that the square variant remains square-ish and the round variant remains round-ish when selected.
| return ''' | ||
| @override | ||
| WidgetStateProperty<EdgeInsetsGeometry>? get padding => | ||
| MaterialStatePropertyAll<EdgeInsetsGeometry>($_paddingSwitch); | ||
|
|
||
| @override | ||
| WidgetStateProperty<Size>? get minimumSize => | ||
| MaterialStatePropertyAll<Size>($_minimumSizeSwitch); | ||
|
|
||
| @override | ||
| WidgetStateProperty<Size>? get maximumSize => | ||
| const MaterialStatePropertyAll<Size>(Size.infinite); | ||
|
|
||
| @override | ||
| WidgetStateProperty<double>? get iconSize => | ||
| MaterialStatePropertyAll<double>($_iconSizeSwitch); | ||
|
|
||
| @override | ||
| WidgetStateProperty<OutlinedBorder>? get shape => | ||
| WidgetStateProperty.resolveWith((Set<WidgetState> states) { | ||
| if (states.contains(WidgetState.pressed)) { | ||
| return $_pressedShapeSwitch; | ||
| } | ||
| if (toggleable && states.contains(WidgetState.selected)) { | ||
| return $_selectedShapeSwitch; | ||
| } | ||
| return $_containerShapeSwitch; | ||
| }); | ||
| '''; |
There was a problem hiding this comment.
Use WidgetStatePropertyAll instead of MaterialStatePropertyAll to align with the WidgetState API migration in Flutter. Since this template generates new code, it should use the modern non-deprecated API.
String get _sizeDependentProperties {
return '''
@override
WidgetStateProperty<EdgeInsetsGeometry>? get padding =>
WidgetStatePropertyAll<EdgeInsetsGeometry>($_paddingSwitch);
@override
WidgetStateProperty<Size>? get minimumSize =>
WidgetStatePropertyAll<Size>($_minimumSizeSwitch);
@override
WidgetStateProperty<Size>? get maximumSize =>
const WidgetStatePropertyAll<Size>(Size.infinite);
@override
WidgetStateProperty<double>? get iconSize =>
WidgetStatePropertyAll<double>($_iconSizeSwitch);
@override
WidgetStateProperty<OutlinedBorder>? get shape =>
WidgetStateProperty.resolveWith((Set<WidgetState> states) {
if (states.contains(WidgetState.pressed)) {
return $_pressedShapeSwitch;
}
if (toggleable && states.contains(WidgetState.selected)) {
return $_selectedShapeSwitch;
}
return $_containerShapeSwitch;
});
''';|
Converting this to draft. Will port this to |
|
Ported the commits to #12832. Closing this PR. |
This PR is to add Material 3 Expressive IconButton support behind an explicit component-level opt-in.
This PR adds:
ButtonStyleproperties used by the IconButton M3E migration:sizeVarianticonButtonWidthshapeVariantIconButtonThemeData.variantsoIconButtonscan opt intoStyleVariant.material3Expressive.IconButtonTemplateM3Eto generateIconButtondefaults from the M3E token data.IconButtondefaults in:packages/material_ui/lib/src/generated/icon_button_defaults_m3e.g.dartTODO:
Pre-launch Checklist
///).