|
| 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 NavigationBarTemplate extends TokenTemplate { |
| 8 | + const NavigationBarTemplate(String fileName, Map<String, dynamic> tokens) : super(fileName, tokens); |
| 9 | + |
| 10 | + @override |
| 11 | + String generate() => ''' |
| 12 | +// Generated version ${tokens["version"]} |
| 13 | +class _TokenDefaultsM3 extends NavigationBarThemeData { |
| 14 | + _TokenDefaultsM3(BuildContext context) |
| 15 | + : _theme = Theme.of(context), |
| 16 | + _colors = Theme.of(context).colorScheme, |
| 17 | + super( |
| 18 | + height: ${tokens["md.comp.navigation-bar.container.height"]}, |
| 19 | + elevation: ${elevation("md.comp.navigation-bar.container")}, |
| 20 | + labelBehavior: NavigationDestinationLabelBehavior.alwaysShow, |
| 21 | + ); |
| 22 | +
|
| 23 | + final ThemeData _theme; |
| 24 | + final ColorScheme _colors; |
| 25 | +
|
| 26 | + // With Material 3, the NavigationBar uses an overlay blend for the |
| 27 | + // default color regardless of light/dark mode. This should be handled |
| 28 | + // in the Material widget based off of elevation, but for now we will do |
| 29 | + // it here in the defaults. |
| 30 | + @override Color? get backgroundColor => ElevationOverlay.colorWithOverlay(_colors.${color("md.comp.navigation-bar.container")}, _colors.primary, ${elevation("md.comp.navigation-bar.container")}); |
| 31 | +
|
| 32 | + @override MaterialStateProperty<IconThemeData?>? get iconTheme { |
| 33 | + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { |
| 34 | + return IconThemeData( |
| 35 | + size: ${tokens["md.comp.navigation-bar.icon.size"]}, |
| 36 | + color: states.contains(MaterialState.selected) |
| 37 | + ? _colors.${color("md.comp.navigation-bar.active.icon")} |
| 38 | + : _colors.${color("md.comp.navigation-bar.inactive.icon")}, |
| 39 | + ); |
| 40 | + }); |
| 41 | + } |
| 42 | +
|
| 43 | + @override Color? get indicatorColor => _colors.${color("md.comp.navigation-bar.active-indicator")}; |
| 44 | + @override ShapeBorder? get indicatorShape => ${shape("md.comp.navigation-bar.active-indicator")}; |
| 45 | +
|
| 46 | + @override MaterialStateProperty<TextStyle?>? get labelTextStyle { |
| 47 | + return MaterialStateProperty.resolveWith((Set<MaterialState> states) { |
| 48 | + final TextStyle style = _theme.textTheme.${textStyle("md.comp.navigation-bar.label-text")}!; |
| 49 | + return style.apply(color: states.contains(MaterialState.selected) |
| 50 | + ? _colors.${color("md.comp.navigation-bar.active.label-text")} |
| 51 | + : _colors.${color("md.comp.navigation-bar.inactive.label-text")} |
| 52 | + ); |
| 53 | + }); |
| 54 | + } |
| 55 | +} |
| 56 | +'''; |
| 57 | +} |
0 commit comments