Skip to content

Commit cfc64d1

Browse files
authored
[material_ui] Migrate M3 PopupMenu template to use new gen_defaults (#13209)
Work toward flutter/flutter#187899. Fixes flutter/flutter#188426. This PR migrates the M3 PopupMenu defaults template to use the new gen_defaults in material_ui. The generated defaults remain unchanged. ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 9fba981 commit cfc64d1

5 files changed

Lines changed: 40 additions & 75 deletions

File tree

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/popup_menu_defaults.g.dart renamed to packages/material_ui/lib/src/generated/popup_menu_defaults_m3.g.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
// Do not edit by hand. The code is generated from data in the Material
6+
// Design token database by the script:
7+
// packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart.
8+
part of '../popup_menu.dart';
9+
510
class _PopupMenuDefaultsM3 extends PopupMenuThemeData {
611
_PopupMenuDefaultsM3(this.context) : super(elevation: 3.0);
712

‎packages/material_ui/lib/src/popup_menu.dart‎

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import 'text_theme.dart';
3131
import 'theme.dart';
3232
import 'tooltip.dart';
3333

34+
part 'generated/popup_menu_defaults_m3.g.dart';
35+
3436
// Examples can assume:
3537
// enum Commands { heroAndScholar, hurricaneCame }
3638
// late bool _heroAndScholar;
@@ -1871,55 +1873,3 @@ class _PopupMenuDefaultsM2 extends PopupMenuThemeData {
18711873

18721874
static EdgeInsets menuItemPadding = const EdgeInsets.symmetric(horizontal: 16.0);
18731875
}
1874-
1875-
// BEGIN GENERATED TOKEN PROPERTIES - PopupMenu
1876-
1877-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
1878-
// "END GENERATED" comments are generated from data in the Material
1879-
// Design token database by the script:
1880-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
1881-
1882-
// dart format off
1883-
class _PopupMenuDefaultsM3 extends PopupMenuThemeData {
1884-
_PopupMenuDefaultsM3(this.context)
1885-
: super(elevation: 3.0);
1886-
1887-
final BuildContext context;
1888-
late final ThemeData _theme = Theme.of(context);
1889-
late final ColorScheme _colors = _theme.colorScheme;
1890-
late final TextTheme _textTheme = _theme.textTheme;
1891-
1892-
@override WidgetStateProperty<TextStyle?>? get labelTextStyle {
1893-
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
1894-
// TODO(quncheng): Update this hard-coded value to use the latest tokens.
1895-
final TextStyle style = _textTheme.labelLarge!;
1896-
if (states.contains(WidgetState.disabled)) {
1897-
return style.apply(color: _colors.onSurface.withOpacity(0.38));
1898-
}
1899-
return style.apply(color: _colors.onSurface);
1900-
});
1901-
}
1902-
1903-
@override
1904-
Color? get color => _colors.surfaceContainer;
1905-
1906-
@override
1907-
Color? get shadowColor => _colors.shadow;
1908-
1909-
@override
1910-
Color? get surfaceTintColor => Colors.transparent;
1911-
1912-
@override
1913-
ShapeBorder? get shape => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
1914-
1915-
// TODO(bleroux): This is taken from https://m3.material.io/components/menus/specs
1916-
// Update this when the token is available.
1917-
@override
1918-
EdgeInsets? get menuPadding => const EdgeInsets.symmetric(vertical: 8.0);
1919-
1920-
// TODO(tahatesser): This is taken from https://m3.material.io/components/menus/specs
1921-
// Update this when the token is available.
1922-
static EdgeInsets menuItemPadding = const EdgeInsets.symmetric(horizontal: 12.0);
1923-
}// dart format on
1924-
1925-
// END GENERATED TOKEN PROPERTIES - PopupMenu

‎packages/material_ui/tool/gen_defaults/bin/gen_defaults.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import '../templates/motion_template.dart';
4040
// import '../templates/navigation_drawer_template.dart';
4141
import '../templates/navigation_rail_template.dart';
4242

43-
// import '../templates/popup_menu_template.dart';
43+
import '../templates/popup_menu_template.dart';
4444
import '../templates/progress_indicator_template.dart';
4545

4646
// import '../templates/radio_template.dart';
@@ -104,7 +104,7 @@ Future<void> main(List<String> args) async {
104104
// const NavigationBarTemplateM3().generateFile(verbose: verbose);
105105
// const NavigationDrawerTemplateM3().generateFile(verbose: verbose);
106106
const NavigationRailTemplateM3().generateFile(verbose: verbose);
107-
// const PopupMenuTemplateM3().generateFile(verbose: verbose);
107+
const PopupMenuTemplateM3().generateFile(verbose: verbose);
108108
const ProgressIndicatorTemplateM3().generateFile(verbose: verbose);
109109
// const RadioTemplateM3().generateFile(verbose: verbose);
110110
const RangeSliderTemplateM3().generateFile(verbose: verbose);

packages/material_ui/tool/gen_defaults/temporarily_excluded/templates/popup_menu_template.dart renamed to packages/material_ui/tool/gen_defaults/templates/popup_menu_template.dart

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import '../data/list.dart';
6+
import '../data/menu.dart';
57
import 'template.dart';
68

7-
class PopupMenuTemplate extends TokenTemplate {
8-
const PopupMenuTemplate(
9-
super.blockName,
10-
super.fileName,
11-
super.tokens, {
12-
super.colorSchemePrefix = '_colors.',
13-
super.textThemePrefix = '_textTheme.',
14-
});
9+
class PopupMenuTemplateM3 extends TokenTemplateM3 {
10+
const PopupMenuTemplateM3();
1511

1612
@override
17-
String generate() =>
13+
String get name => 'Popup Menu';
14+
15+
@override
16+
String get parentFilePath => 'popup_menu.dart';
17+
18+
@override
19+
String generateContents(String className) =>
1820
'''
19-
class _${blockName}DefaultsM3 extends PopupMenuThemeData {
20-
_${blockName}DefaultsM3(this.context)
21-
: super(elevation: ${elevation('md.comp.menu.container')});
21+
class $className extends PopupMenuThemeData {
22+
$className(this.context)
23+
: super(elevation: ${TokenMenu.containerElevation});
2224
2325
final BuildContext context;
2426
late final ThemeData _theme = Theme.of(context);
@@ -30,23 +32,23 @@ class _${blockName}DefaultsM3 extends PopupMenuThemeData {
3032
// TODO(quncheng): Update this hard-coded value to use the latest tokens.
3133
final TextStyle style = _textTheme.labelLarge!;
3234
if (states.contains(WidgetState.disabled)) {
33-
return style.apply(color: ${componentColor('md.comp.list.list-item.disabled.label-text')});
35+
return style.apply(color: ${colorWithOpacity(TokenList.listItemDisabledLabelTextColor, TokenList.listItemDisabledLabelTextOpacity)});
3436
}
35-
return style.apply(color: ${componentColor('md.comp.list.list-item.label-text')});
37+
return style.apply(color: ${color(TokenList.listItemLabelTextColor)});
3638
});
3739
}
3840
3941
@override
40-
Color? get color => ${componentColor('md.comp.menu.container')};
42+
Color? get color => ${color(TokenMenu.containerColor)};
4143
4244
@override
43-
Color? get shadowColor => ${color("md.comp.menu.container.shadow-color")};
45+
Color? get shadowColor => ${color(TokenMenu.containerShadowColor)};
4446
4547
@override
46-
Color? get surfaceTintColor => ${colorOrTransparent("md.comp.menu.container.surface-tint-layer.color")};
48+
Color? get surfaceTintColor => Colors.transparent;
4749
4850
@override
49-
ShapeBorder? get shape => ${shape("md.comp.menu.container")};
51+
ShapeBorder? get shape => ${shape(TokenMenu.containerShape)};
5052
5153
// TODO(bleroux): This is taken from https://m3.material.io/components/menus/specs
5254
// Update this when the token is available.

‎packages/material_ui/tool/gen_defaults/test/gen_defaults_test.dart‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import '../templates/motion_template.dart';
3737
// import '../templates/navigation_bar_template.dart';
3838
// import '../templates/navigation_drawer_template.dart';
3939
import '../templates/navigation_rail_template.dart';
40-
// import '../templates/popup_menu_template.dart';
40+
import '../templates/popup_menu_template.dart';
4141
import '../templates/progress_indicator_template.dart';
4242
// import '../templates/radio_template.dart';
4343
import '../templates/range_slider_template.dart';
@@ -750,8 +750,16 @@ void main() {
750750
});
751751

752752
test('PopupMenuTemplateM3 emits M3 PopupMenu defaults from tokens', () {
753-
// Intentionally empty, will be implemented during migration. See:
754-
// https://github.com/flutter/flutter/issues/187899
753+
final String contents = _generateContents(const PopupMenuTemplateM3());
754+
expect(contents, contains('super(elevation: 3.0)'));
755+
expect(contents, contains('_colors.onSurface.withOpacity(0.38)'));
756+
expect(contents, contains('Color? get color => _colors.surfaceContainer;'));
757+
expect(
758+
contents,
759+
contains(
760+
'ShapeBorder? get shape => const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)))',
761+
),
762+
);
755763
});
756764

757765
test('ProgressIndicatorTemplateM3 emits M3 ProgressIndicator defaults from tokens', () {

0 commit comments

Comments
 (0)