Migrate NavigationRail to Material 3. (#99171)
This commit is contained in:
@@ -20,6 +20,7 @@ import 'dart:io';
|
||||
import 'package:gen_defaults/dialog_template.dart';
|
||||
import 'package:gen_defaults/fab_template.dart';
|
||||
import 'package:gen_defaults/navigation_bar_template.dart';
|
||||
import 'package:gen_defaults/navigation_rail_template.dart';
|
||||
import 'package:gen_defaults/typography_template.dart';
|
||||
|
||||
Map<String, dynamic> _readTokenFile(String fileName) {
|
||||
@@ -45,6 +46,7 @@ Future<void> main(List<String> args) async {
|
||||
'input_chip.json',
|
||||
'motion.json',
|
||||
'navigation_bar.json',
|
||||
'navigation_rail.json',
|
||||
'outlined_card.json',
|
||||
'palette.json',
|
||||
'shape.json',
|
||||
@@ -70,6 +72,7 @@ Future<void> main(List<String> args) async {
|
||||
|
||||
FABTemplate('$materialLib/floating_action_button.dart', tokens).updateFile();
|
||||
NavigationBarTemplate('$materialLib/navigation_bar.dart', tokens).updateFile();
|
||||
NavigationRailTemplate('$materialLib/navigation_rail.dart', tokens).updateFile();
|
||||
TypographyTemplate('$materialLib/typography.dart', tokens).updateFile();
|
||||
DialogTemplate('$materialLib/dialog.dart', tokens).updateFile();
|
||||
}
|
||||
|
||||
57
dev/tools/gen_defaults/lib/navigation_rail_template.dart
Normal file
57
dev/tools/gen_defaults/lib/navigation_rail_template.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'template.dart';
|
||||
|
||||
class NavigationRailTemplate extends TokenTemplate {
|
||||
const NavigationRailTemplate(String fileName, Map<String, dynamic> tokens) : super(fileName, tokens);
|
||||
|
||||
@override
|
||||
String generate() => '''
|
||||
// Generated version ${tokens["version"]}
|
||||
class _TokenDefaultsM3 extends NavigationRailThemeData {
|
||||
_TokenDefaultsM3(BuildContext context)
|
||||
: _theme = Theme.of(context),
|
||||
_colors = Theme.of(context).colorScheme,
|
||||
super(
|
||||
elevation: ${elevation("md.comp.navigation-rail.container")},
|
||||
groupAlignment: -1,
|
||||
labelType: NavigationRailLabelType.none,
|
||||
useIndicator: true,
|
||||
minWidth: ${tokens["md.comp.navigation-rail.container.width"]},
|
||||
minExtendedWidth: 256,
|
||||
);
|
||||
|
||||
final ThemeData _theme;
|
||||
final ColorScheme _colors;
|
||||
|
||||
@override Color? get backgroundColor => _colors.${color("md.comp.navigation-rail.container")};
|
||||
|
||||
@override TextStyle? get unselectedLabelTextStyle {
|
||||
return _theme.textTheme.${textStyle("md.comp.navigation-rail.label-text")}!.copyWith(color: _colors.${color("md.comp.navigation-rail.inactive.focus.label-text")});
|
||||
}
|
||||
|
||||
@override TextStyle? get selectedLabelTextStyle {
|
||||
return _theme.textTheme.${textStyle("md.comp.navigation-rail.label-text")}!.copyWith(color: _colors.${color("md.comp.navigation-rail.active.focus.label-text")});
|
||||
}
|
||||
|
||||
@override IconThemeData? get unselectedIconTheme {
|
||||
return IconThemeData(
|
||||
size: ${tokens["md.comp.navigation-rail.icon.size"]},
|
||||
color: _colors.${color("md.comp.navigation-rail.inactive.icon")},
|
||||
);
|
||||
}
|
||||
|
||||
@override IconThemeData? get selectedIconTheme {
|
||||
return IconThemeData(
|
||||
size: ${tokens["md.comp.navigation-rail.icon.size"]},
|
||||
color: _colors.${color("md.comp.navigation-rail.active.icon")},
|
||||
);
|
||||
}
|
||||
|
||||
@override Color? get indicatorColor => _colors.${color("md.comp.navigation-rail.active-indicator")};
|
||||
|
||||
}
|
||||
''';
|
||||
}
|
||||
Reference in New Issue
Block a user