Skip to content

Commit 9b05755

Browse files
authored
[material_ui] Migrate M3 NavigationBar template to use new gen_defaults (#13067)
Work toward flutter/flutter#187899. Fixes flutter/flutter#188423. This PR migrates the M3 NavigationBar 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 ecf4f2f commit 9b05755

6 files changed

Lines changed: 102 additions & 153 deletions

File tree

packages/material_ui/tool/gen_defaults/temporarily_excluded/generated/navigation_bar_defaults.g.dart renamed to packages/material_ui/lib/src/generated/navigation_bar_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_bar.dart';
9+
510
class _NavigationBarDefaultsM3 extends NavigationBarThemeData {
611
_NavigationBarDefaultsM3(this.context)
712
: super(

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

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import 'text_theme.dart';
2626
import 'theme.dart';
2727
import 'tooltip.dart';
2828

29+
part 'generated/navigation_bar_defaults_m3.g.dart';
30+
2931
const double _kIndicatorHeight = 32;
3032
const double _kIndicatorWidth = 64;
3133
const double _kMaxLabelTextScaleFactor = 1.3;
@@ -1442,73 +1444,3 @@ class _NavigationBarDefaultsM2 extends NavigationBarThemeData {
14421444
@override
14431445
EdgeInsetsGeometry? get labelPadding => const EdgeInsets.only(top: 4);
14441446
}
1445-
1446-
// BEGIN GENERATED TOKEN PROPERTIES - NavigationBar
1447-
1448-
// Do not edit by hand. The code between the "BEGIN GENERATED" and
1449-
// "END GENERATED" comments are generated from data in the Material
1450-
// Design token database by the script:
1451-
// dev/tools/gen_defaults/bin/gen_defaults.dart.
1452-
1453-
// dart format off
1454-
class _NavigationBarDefaultsM3 extends NavigationBarThemeData {
1455-
_NavigationBarDefaultsM3(this.context)
1456-
: super(
1457-
height: 80.0,
1458-
elevation: 3.0,
1459-
labelBehavior: NavigationDestinationLabelBehavior.alwaysShow,
1460-
);
1461-
1462-
final BuildContext context;
1463-
late final ColorScheme _colors = Theme.of(context).colorScheme;
1464-
late final TextTheme _textTheme = Theme.of(context).textTheme;
1465-
1466-
@override
1467-
Color? get backgroundColor => _colors.surfaceContainer;
1468-
1469-
@override
1470-
Color? get shadowColor => Colors.transparent;
1471-
1472-
@override
1473-
Color? get surfaceTintColor => Colors.transparent;
1474-
1475-
@override
1476-
WidgetStateProperty<IconThemeData?>? get iconTheme {
1477-
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
1478-
return IconThemeData(
1479-
size: 24.0,
1480-
color: states.contains(WidgetState.disabled)
1481-
? _colors.onSurfaceVariant.withOpacity(0.38)
1482-
: states.contains(WidgetState.selected)
1483-
? _colors.onSecondaryContainer
1484-
: _colors.onSurfaceVariant,
1485-
);
1486-
});
1487-
}
1488-
1489-
@override
1490-
Color? get indicatorColor => _colors.secondaryContainer;
1491-
1492-
@override
1493-
ShapeBorder? get indicatorShape => const StadiumBorder();
1494-
1495-
@override
1496-
WidgetStateProperty<TextStyle?>? get labelTextStyle {
1497-
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
1498-
final TextStyle style = _textTheme.labelMedium!;
1499-
return style.apply(
1500-
color: states.contains(WidgetState.disabled)
1501-
? _colors.onSurfaceVariant.withOpacity(0.38)
1502-
: states.contains(WidgetState.selected)
1503-
? _colors.onSurface
1504-
: _colors.onSurfaceVariant
1505-
);
1506-
});
1507-
}
1508-
1509-
@override
1510-
EdgeInsetsGeometry? get labelPadding => const EdgeInsets.only(top: 4);
1511-
}
1512-
// dart format on
1513-
1514-
// END GENERATED TOKEN PROPERTIES - NavigationBar

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import '../templates/input_decorator_template.dart';
3636
import '../templates/list_tile_template.dart';
3737
import '../templates/menu_template.dart';
3838
import '../templates/motion_template.dart';
39-
// import '../templates/navigation_bar_template.dart';
39+
import '../templates/navigation_bar_template.dart';
4040
import '../templates/navigation_drawer_template.dart';
4141
import '../templates/navigation_rail_template.dart';
4242

@@ -100,7 +100,7 @@ Future<void> main(List<String> args) async {
100100
const ListTileTemplateM3().generateFile(verbose: verbose);
101101
const MenuTemplateM3().generateFile(verbose: verbose);
102102
const MotionTemplateM3().generateFile(verbose: verbose);
103-
// const NavigationBarTemplateM3().generateFile(verbose: verbose);
103+
const NavigationBarTemplateM3().generateFile(verbose: verbose);
104104
const NavigationDrawerTemplateM3().generateFile(verbose: verbose);
105105
const NavigationRailTemplateM3().generateFile(verbose: verbose);
106106
const PopupMenuTemplateM3().generateFile(verbose: verbose);
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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/color_role.dart';
6+
import '../data/navigation_bar.dart';
7+
import 'template.dart';
8+
9+
class NavigationBarTemplateM3 extends TokenTemplateM3 {
10+
const NavigationBarTemplateM3();
11+
12+
@override
13+
String get name => 'Navigation Bar';
14+
15+
@override
16+
String get parentFilePath => 'navigation_bar.dart';
17+
18+
// TODO(QuncCccccc): Replace these with token values once disabled-state
19+
// tokens are available.
20+
static const TokenColorRole _legacyDisabledColor = TokenColorRole.onSurfaceVariant;
21+
static const double _legacyDisabledOpacity = 0.38;
22+
23+
@override
24+
String generateContents(String className) =>
25+
'''
26+
class $className extends NavigationBarThemeData {
27+
$className(this.context)
28+
: super(
29+
height: ${number(TokenNavigationBar.containerHeight)},
30+
elevation: ${number(TokenNavigationBar.containerElevation)},
31+
labelBehavior: NavigationDestinationLabelBehavior.alwaysShow,
32+
);
33+
34+
final BuildContext context;
35+
late final ColorScheme _colors = Theme.of(context).colorScheme;
36+
late final TextTheme _textTheme = Theme.of(context).textTheme;
37+
38+
@override
39+
Color? get backgroundColor => ${color(TokenNavigationBar.containerColor)};
40+
41+
@override
42+
Color? get shadowColor => Colors.transparent;
43+
44+
@override
45+
Color? get surfaceTintColor => Colors.transparent;
46+
47+
@override
48+
WidgetStateProperty<IconThemeData?>? get iconTheme {
49+
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
50+
return IconThemeData(
51+
size: ${number(TokenNavigationBar.iconSize)},
52+
color: states.contains(WidgetState.disabled)
53+
? ${colorWithOpacity(_legacyDisabledColor, _legacyDisabledOpacity)}
54+
: states.contains(WidgetState.selected)
55+
? ${color(TokenNavigationBar.activeIconColor)}
56+
: ${color(TokenNavigationBar.inactiveIconColor)},
57+
);
58+
});
59+
}
60+
61+
@override
62+
Color? get indicatorColor => ${color(TokenNavigationBar.activeIndicatorColor)};
63+
64+
@override
65+
ShapeBorder? get indicatorShape => ${shape(TokenNavigationBar.activeIndicatorShape)};
66+
67+
@override
68+
WidgetStateProperty<TextStyle?>? get labelTextStyle {
69+
return WidgetStateProperty.resolveWith((Set<WidgetState> states) {
70+
final TextStyle style = ${textStyle(TokenNavigationBar.labelTextType, '_textTheme')}!;
71+
return style.apply(
72+
color: states.contains(WidgetState.disabled)
73+
? ${colorWithOpacity(_legacyDisabledColor, _legacyDisabledOpacity)}
74+
: states.contains(WidgetState.selected)
75+
? ${color(TokenNavigationBar.activeLabelTextColor)}
76+
: ${color(TokenNavigationBar.inactiveLabelTextColor)},
77+
);
78+
});
79+
}
80+
81+
@override
82+
EdgeInsetsGeometry? get labelPadding => const EdgeInsets.only(top: 4);
83+
}
84+
''';
85+
}

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

Lines changed: 0 additions & 78 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
@@ -34,7 +34,7 @@ import '../templates/input_decorator_template.dart';
3434
import '../templates/list_tile_template.dart';
3535
import '../templates/menu_template.dart';
3636
import '../templates/motion_template.dart';
37-
// import '../templates/navigation_bar_template.dart';
37+
import '../templates/navigation_bar_template.dart';
3838
import '../templates/navigation_drawer_template.dart';
3939
import '../templates/navigation_rail_template.dart';
4040
import '../templates/popup_menu_template.dart';
@@ -729,8 +729,13 @@ void main() {
729729
});
730730

731731
test('NavigationBarTemplateM3 emits M3 NavigationBar defaults from tokens', () {
732-
// Intentionally empty, will be implemented during migration. See:
733-
// https://github.com/flutter/flutter/issues/187899
732+
const template = NavigationBarTemplateM3();
733+
final String contents = _generateContents(template);
734+
expect(contents, contains('class _NavigationBarDefaultsM3 extends NavigationBarThemeData'));
735+
expect(contents, contains('height: 80.0'));
736+
expect(contents, contains('_colors.surfaceContainer'));
737+
expect(contents, contains('_colors.onSurfaceVariant.withOpacity(0.38)'));
738+
expect(contents, contains('ShapeBorder? get indicatorShape => const StadiumBorder()'));
734739
});
735740

736741
test('NavigationDrawerTemplateM3 emits M3 NavigationDrawer defaults from tokens', () {

0 commit comments

Comments
 (0)