Skip to content

Commit 57aa490

Browse files
authored
Migrate NavigationRail to Material 3. (#99171)
1 parent 9291c8b commit 57aa490

7 files changed

Lines changed: 2625 additions & 517 deletions

File tree

dev/tools/gen_defaults/bin/gen_defaults.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'dart:io';
2020
import 'package:gen_defaults/dialog_template.dart';
2121
import 'package:gen_defaults/fab_template.dart';
2222
import 'package:gen_defaults/navigation_bar_template.dart';
23+
import 'package:gen_defaults/navigation_rail_template.dart';
2324
import 'package:gen_defaults/typography_template.dart';
2425

2526
Map<String, dynamic> _readTokenFile(String fileName) {
@@ -45,6 +46,7 @@ Future<void> main(List<String> args) async {
4546
'input_chip.json',
4647
'motion.json',
4748
'navigation_bar.json',
49+
'navigation_rail.json',
4850
'outlined_card.json',
4951
'palette.json',
5052
'shape.json',
@@ -70,6 +72,7 @@ Future<void> main(List<String> args) async {
7072

7173
FABTemplate('$materialLib/floating_action_button.dart', tokens).updateFile();
7274
NavigationBarTemplate('$materialLib/navigation_bar.dart', tokens).updateFile();
75+
NavigationRailTemplate('$materialLib/navigation_rail.dart', tokens).updateFile();
7376
TypographyTemplate('$materialLib/typography.dart', tokens).updateFile();
7477
DialogTemplate('$materialLib/dialog.dart', tokens).updateFile();
7578
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
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 'template.dart';
6+
7+
class NavigationRailTemplate extends TokenTemplate {
8+
const NavigationRailTemplate(String fileName, Map<String, dynamic> tokens) : super(fileName, tokens);
9+
10+
@override
11+
String generate() => '''
12+
// Generated version ${tokens["version"]}
13+
class _TokenDefaultsM3 extends NavigationRailThemeData {
14+
_TokenDefaultsM3(BuildContext context)
15+
: _theme = Theme.of(context),
16+
_colors = Theme.of(context).colorScheme,
17+
super(
18+
elevation: ${elevation("md.comp.navigation-rail.container")},
19+
groupAlignment: -1,
20+
labelType: NavigationRailLabelType.none,
21+
useIndicator: true,
22+
minWidth: ${tokens["md.comp.navigation-rail.container.width"]},
23+
minExtendedWidth: 256,
24+
);
25+
26+
final ThemeData _theme;
27+
final ColorScheme _colors;
28+
29+
@override Color? get backgroundColor => _colors.${color("md.comp.navigation-rail.container")};
30+
31+
@override TextStyle? get unselectedLabelTextStyle {
32+
return _theme.textTheme.${textStyle("md.comp.navigation-rail.label-text")}!.copyWith(color: _colors.${color("md.comp.navigation-rail.inactive.focus.label-text")});
33+
}
34+
35+
@override TextStyle? get selectedLabelTextStyle {
36+
return _theme.textTheme.${textStyle("md.comp.navigation-rail.label-text")}!.copyWith(color: _colors.${color("md.comp.navigation-rail.active.focus.label-text")});
37+
}
38+
39+
@override IconThemeData? get unselectedIconTheme {
40+
return IconThemeData(
41+
size: ${tokens["md.comp.navigation-rail.icon.size"]},
42+
color: _colors.${color("md.comp.navigation-rail.inactive.icon")},
43+
);
44+
}
45+
46+
@override IconThemeData? get selectedIconTheme {
47+
return IconThemeData(
48+
size: ${tokens["md.comp.navigation-rail.icon.size"]},
49+
color: _colors.${color("md.comp.navigation-rail.active.icon")},
50+
);
51+
}
52+
53+
@override Color? get indicatorColor => _colors.${color("md.comp.navigation-rail.active-indicator")};
54+
55+
}
56+
''';
57+
}

0 commit comments

Comments
 (0)