|
| 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 | +} |
0 commit comments