|
| 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_drawer.dart'; |
| 7 | +import 'template.dart'; |
| 8 | + |
| 9 | +class NavigationDrawerTemplateM3 extends TokenTemplateM3 { |
| 10 | + const NavigationDrawerTemplateM3(); |
| 11 | + |
| 12 | + @override |
| 13 | + String get name => 'Navigation Drawer'; |
| 14 | + |
| 15 | + @override |
| 16 | + String get parentFilePath => 'navigation_drawer.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 NavigationDrawerThemeData { |
| 27 | + $className(this.context) |
| 28 | + : super( |
| 29 | + elevation: ${number(TokenNavigationDrawer.modalContainerElevation)}, |
| 30 | + tileHeight: ${number(TokenNavigationDrawer.activeIndicatorHeight)}, |
| 31 | + indicatorShape: ${shape(TokenNavigationDrawer.activeIndicatorShape)}, |
| 32 | + indicatorSize: const Size(${number(TokenNavigationDrawer.activeIndicatorWidth)}, ${number(TokenNavigationDrawer.activeIndicatorHeight)}), |
| 33 | + ); |
| 34 | +
|
| 35 | + final BuildContext context; |
| 36 | + late final ColorScheme _colors = Theme.of(context).colorScheme; |
| 37 | + late final TextTheme _textTheme = Theme.of(context).textTheme; |
| 38 | +
|
| 39 | + @override |
| 40 | + Color? get backgroundColor => ${color(TokenNavigationDrawer.modalContainerColor)}; |
| 41 | +
|
| 42 | + @override |
| 43 | + Color? get surfaceTintColor => Colors.transparent; |
| 44 | +
|
| 45 | + @override |
| 46 | + Color? get shadowColor => Colors.transparent; |
| 47 | +
|
| 48 | + @override |
| 49 | + Color? get indicatorColor => ${color(TokenNavigationDrawer.activeIndicatorColor)}; |
| 50 | +
|
| 51 | + @override |
| 52 | + WidgetStateProperty<IconThemeData?>? get iconTheme { |
| 53 | + return WidgetStateProperty.resolveWith((Set<WidgetState> states) { |
| 54 | + return IconThemeData( |
| 55 | + size: ${number(TokenNavigationDrawer.iconSize)}, |
| 56 | + color: states.contains(WidgetState.disabled) |
| 57 | + ? ${colorWithOpacity(_legacyDisabledColor, _legacyDisabledOpacity)} |
| 58 | + : states.contains(WidgetState.selected) |
| 59 | + ? ${color(TokenNavigationDrawer.activeIconColor)} |
| 60 | + : ${color(TokenNavigationDrawer.inactiveIconColor)}, |
| 61 | + ); |
| 62 | + }); |
| 63 | + } |
| 64 | +
|
| 65 | + @override |
| 66 | + WidgetStateProperty<TextStyle?>? get labelTextStyle { |
| 67 | + return WidgetStateProperty.resolveWith((Set<WidgetState> states) { |
| 68 | + final TextStyle style = ${textStyle(TokenNavigationDrawer.labelTextType, '_textTheme')}!; |
| 69 | + return style.apply( |
| 70 | + color: states.contains(WidgetState.disabled) |
| 71 | + ? ${colorWithOpacity(_legacyDisabledColor, _legacyDisabledOpacity)} |
| 72 | + : states.contains(WidgetState.selected) |
| 73 | + ? ${color(TokenNavigationDrawer.activeLabelTextColor)} |
| 74 | + : ${color(TokenNavigationDrawer.inactiveLabelTextColor)}, |
| 75 | + ); |
| 76 | + }); |
| 77 | + } |
| 78 | +} |
| 79 | +'''; |
| 80 | +} |
0 commit comments