Skip to content

Commit a40053c

Browse files
authored
[material_ui] Migrate M3 NavigationRail template to use new gen_defaults (#13069)
Work toward flutter/flutter#187899. Fixes flutter/flutter#188425. This PR migrates the M3 NavigationRail 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 5de92e4 commit a40053c

6 files changed

Lines changed: 89 additions & 123 deletions

File tree

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/navigation_rail_defaults.g.dart renamed to packages/material_ui/lib/src/generated/navigation_rail_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 '../navigation_rail.dart';
9+
510
class _NavigationRailDefaultsM3 extends NavigationRailThemeData {
611
_NavigationRailDefaultsM3(this.context)
712
: super(

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

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import 'navigation_rail_theme.dart';
2121
import 'text_theme.dart';
2222
import 'theme.dart';
2323

24+
part 'generated/navigation_rail_defaults_m3.g.dart';
25+
2426
const double _kCircularIndicatorDiameter = 56;
2527
const double _kIndicatorHeight = 32;
2628

@@ -1233,58 +1235,3 @@ class _NavigationRailDefaultsM2 extends NavigationRailThemeData {
12331235
return IconThemeData(size: 24.0, color: _colors.primary, opacity: 1.0);
12341236
}
12351237
}
1236-
1237-
// BEGIN GENERATED TOKEN PROPERTIES - NavigationRail
1238-
1239-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
1240-
// "END GENERATED" comments are generated from data in the Material
1241-
// Design token database by the script:
1242-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
1243-
1244-
// dart format off
1245-
class _NavigationRailDefaultsM3 extends NavigationRailThemeData {
1246-
_NavigationRailDefaultsM3(this.context)
1247-
: super(
1248-
elevation: 0.0,
1249-
groupAlignment: -1,
1250-
labelType: NavigationRailLabelType.none,
1251-
useIndicator: true,
1252-
minWidth: 80.0,
1253-
minExtendedWidth: 256,
1254-
);
1255-
1256-
final BuildContext context;
1257-
late final ColorScheme _colors = Theme.of(context).colorScheme;
1258-
late final TextTheme _textTheme = Theme.of(context).textTheme;
1259-
1260-
@override Color? get backgroundColor => _colors.surface;
1261-
1262-
@override TextStyle? get unselectedLabelTextStyle {
1263-
return _textTheme.labelMedium!.copyWith(color: _colors.onSurface);
1264-
}
1265-
1266-
@override TextStyle? get selectedLabelTextStyle {
1267-
return _textTheme.labelMedium!.copyWith(color: _colors.onSurface);
1268-
}
1269-
1270-
@override IconThemeData? get unselectedIconTheme {
1271-
return IconThemeData(
1272-
size: 24.0,
1273-
color: _colors.onSurfaceVariant,
1274-
);
1275-
}
1276-
1277-
@override IconThemeData? get selectedIconTheme {
1278-
return IconThemeData(
1279-
size: 24.0,
1280-
color: _colors.onSecondaryContainer,
1281-
);
1282-
}
1283-
1284-
@override Color? get indicatorColor => _colors.secondaryContainer;
1285-
1286-
@override ShapeBorder? get indicatorShape => const StadiumBorder();
1287-
}
1288-
// dart format on
1289-
1290-
// END GENERATED TOKEN PROPERTIES - NavigationRail

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ import '../templates/menu_template.dart';
3838
import '../templates/motion_template.dart';
3939
// import '../templates/navigation_bar_template.dart';
4040
// import '../templates/navigation_drawer_template.dart';
41-
// import '../templates/navigation_rail_template.dart';
41+
import '../templates/navigation_rail_template.dart';
42+
4243
// import '../templates/popup_menu_template.dart';
4344
import '../templates/progress_indicator_template.dart';
4445

@@ -102,7 +103,7 @@ Future<void> main(List<String> args) async {
102103
const MotionTemplateM3().generateFile(verbose: verbose);
103104
// const NavigationBarTemplateM3().generateFile(verbose: verbose);
104105
// const NavigationDrawerTemplateM3().generateFile(verbose: verbose);
105-
// const NavigationRailTemplateM3().generateFile(verbose: verbose);
106+
const NavigationRailTemplateM3().generateFile(verbose: verbose);
106107
// const PopupMenuTemplateM3().generateFile(verbose: verbose);
107108
const ProgressIndicatorTemplateM3().generateFile(verbose: verbose);
108109
// const RadioTemplateM3().generateFile(verbose: verbose);
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import '../data/navigation_rail.dart';
6+
import 'template.dart';
7+
8+
class NavigationRailTemplateM3 extends TokenTemplateM3 {
9+
const NavigationRailTemplateM3();
10+
11+
@override
12+
String get name => 'Navigation Rail';
13+
14+
@override
15+
String get parentFilePath => 'navigation_rail.dart';
16+
17+
@override
18+
String generateContents(String className) =>
19+
'''
20+
class $className extends NavigationRailThemeData {
21+
$className(this.context)
22+
: super(
23+
elevation: ${number(TokenNavigationRail.containerElevation)},
24+
groupAlignment: -1,
25+
labelType: NavigationRailLabelType.none,
26+
useIndicator: true,
27+
minWidth: ${number(TokenNavigationRail.containerWidth)},
28+
minExtendedWidth: 256,
29+
);
30+
31+
final BuildContext context;
32+
late final ColorScheme _colors = Theme.of(context).colorScheme;
33+
late final TextTheme _textTheme = Theme.of(context).textTheme;
34+
35+
@override
36+
Color? get backgroundColor => ${color(TokenNavigationRail.containerColor)};
37+
38+
@override
39+
TextStyle? get unselectedLabelTextStyle {
40+
return ${textStyle(TokenNavigationRail.labelTextType, '_textTheme')}!.copyWith(color: ${color(TokenNavigationRail.inactiveFocusLabelTextColor)});
41+
}
42+
43+
@override
44+
TextStyle? get selectedLabelTextStyle {
45+
return ${textStyle(TokenNavigationRail.labelTextType, '_textTheme')}!.copyWith(color: ${color(TokenNavigationRail.activeFocusLabelTextColor)});
46+
}
47+
48+
@override
49+
IconThemeData? get unselectedIconTheme {
50+
return IconThemeData(
51+
size: ${number(TokenNavigationRail.iconSize)},
52+
color: ${color(TokenNavigationRail.inactiveIconColor)},
53+
);
54+
}
55+
56+
@override
57+
IconThemeData? get selectedIconTheme {
58+
return IconThemeData(
59+
size: ${number(TokenNavigationRail.iconSize)},
60+
color: ${color(TokenNavigationRail.activeIconColor)},
61+
);
62+
}
63+
64+
@override
65+
Color? get indicatorColor => ${color(TokenNavigationRail.activeIndicatorColor)};
66+
67+
@override
68+
ShapeBorder? get indicatorShape => ${shape(TokenNavigationRail.activeIndicatorShape)};
69+
}
70+
''';
71+
}

‎packages/material_ui/tool/gen_defaults/temporarily_excluded/templates/navigation_rail_template.dart‎

Lines changed: 0 additions & 63 deletions
This file was deleted.

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import '../templates/menu_template.dart';
3636
import '../templates/motion_template.dart';
3737
// import '../templates/navigation_bar_template.dart';
3838
// import '../templates/navigation_drawer_template.dart';
39-
// import '../templates/navigation_rail_template.dart';
39+
import '../templates/navigation_rail_template.dart';
4040
// import '../templates/popup_menu_template.dart';
4141
import '../templates/progress_indicator_template.dart';
4242
// import '../templates/radio_template.dart';
@@ -740,8 +740,13 @@ void main() {
740740
});
741741

742742
test('NavigationRailTemplateM3 emits M3 NavigationRail defaults from tokens', () {
743-
// Intentionally empty, will be implemented during migration. See:
744-
// https://github.com/flutter/flutter/issues/187899
743+
const template = NavigationRailTemplateM3();
744+
final String contents = _generateContents(template);
745+
expect(contents, contains('class _NavigationRailDefaultsM3 extends NavigationRailThemeData'));
746+
expect(contents, contains('minWidth: 80.0'));
747+
expect(contents, contains('Color? get backgroundColor => _colors.surface'));
748+
expect(contents, contains('color: _colors.onSurfaceVariant'));
749+
expect(contents, contains('ShapeBorder? get indicatorShape => const StadiumBorder()'));
745750
});
746751

747752
test('PopupMenuTemplateM3 emits M3 PopupMenu defaults from tokens', () {

0 commit comments

Comments
 (0)