|
| 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/app_bar.dart'; |
| 6 | +import '../data/app_bar_large.dart'; |
| 7 | +import '../data/app_bar_medium.dart'; |
| 8 | +import '../data/app_bar_small.dart'; |
| 9 | +import 'template.dart'; |
| 10 | + |
| 11 | +class AppBarTemplateM3 extends TokenTemplateM3 { |
| 12 | + const AppBarTemplateM3(); |
| 13 | + |
| 14 | + @override |
| 15 | + String get name => 'App Bar'; |
| 16 | + |
| 17 | + @override |
| 18 | + String get parentFilePath => 'app_bar.dart'; |
| 19 | + |
| 20 | + @override |
| 21 | + String generateContents(String className) => |
| 22 | + ''' |
| 23 | +class $className extends AppBarThemeData { |
| 24 | + $className(this.context) |
| 25 | + : super( |
| 26 | + elevation: ${number(TokenAppBar.containerElevation)}, |
| 27 | + scrolledUnderElevation: ${number(TokenAppBar.onScrollContainerElevation)}, |
| 28 | + titleSpacing: NavigationToolbar.kMiddleSpacing, |
| 29 | + toolbarHeight: ${number(TokenAppBarSmall.containerHeight)}, |
| 30 | + ); |
| 31 | +
|
| 32 | + final BuildContext context; |
| 33 | + late final ThemeData _theme = Theme.of(context); |
| 34 | + late final ColorScheme _colors = _theme.colorScheme; |
| 35 | + late final TextTheme _textTheme = _theme.textTheme; |
| 36 | +
|
| 37 | + @override |
| 38 | + Color? get backgroundColor => ${color(TokenAppBar.containerColor, '_colors')}; |
| 39 | +
|
| 40 | + @override |
| 41 | + Color? get foregroundColor => ${color(TokenAppBar.titleColor, '_colors')}; |
| 42 | +
|
| 43 | + @override |
| 44 | + Color? get shadowColor => Colors.transparent; |
| 45 | +
|
| 46 | + @override |
| 47 | + Color? get surfaceTintColor => Colors.transparent; |
| 48 | +
|
| 49 | + @override |
| 50 | + IconThemeData? get iconTheme => IconThemeData( |
| 51 | + color: ${color(TokenAppBar.leadingIconColor, '_colors')}, |
| 52 | + size: ${number(TokenAppBar.iconSize)}, |
| 53 | + ); |
| 54 | +
|
| 55 | + @override |
| 56 | + IconThemeData? get actionsIconTheme => IconThemeData( |
| 57 | + color: ${color(TokenAppBar.trailingIconColor, '_colors')}, |
| 58 | + size: ${number(TokenAppBar.iconSize)}, |
| 59 | + ); |
| 60 | +
|
| 61 | + @override |
| 62 | + TextStyle? get toolbarTextStyle => _textTheme.bodyMedium; |
| 63 | +
|
| 64 | + @override |
| 65 | + TextStyle? get titleTextStyle => _textTheme.titleLarge; |
| 66 | +
|
| 67 | + // TODO(Craftplacer): Consider using EdgeInsets.only(right: 8.0) instead of |
| 68 | + // EdgeInsets.zero for Material 3 in the future, |
| 69 | + // https://github.com/flutter/flutter/issues/155747 |
| 70 | + @override |
| 71 | + EdgeInsets? get actionsPadding => EdgeInsets.zero; |
| 72 | +} |
| 73 | +
|
| 74 | +// Variant configuration |
| 75 | +class _MediumScrollUnderFlexibleConfig with _ScrollUnderFlexibleConfig { |
| 76 | + _MediumScrollUnderFlexibleConfig(this.context); |
| 77 | +
|
| 78 | + final BuildContext context; |
| 79 | + late final ThemeData _theme = Theme.of(context); |
| 80 | + late final ColorScheme _colors = _theme.colorScheme; |
| 81 | + late final TextTheme _textTheme = _theme.textTheme; |
| 82 | +
|
| 83 | + static const double collapsedHeight = ${number(TokenAppBarSmall.containerHeight)}; |
| 84 | + static const double expandedHeight = ${number(TokenAppBarMedium.containerHeight)}; |
| 85 | +
|
| 86 | + @override |
| 87 | + TextStyle? get collapsedTextStyle => |
| 88 | + _textTheme.titleLarge?.apply(color: ${color(TokenAppBar.titleColor, '_colors')}); |
| 89 | +
|
| 90 | + @override |
| 91 | + TextStyle? get expandedTextStyle => |
| 92 | + _textTheme.headlineSmall?.apply(color: ${color(TokenAppBar.titleColor, '_colors')}); |
| 93 | +
|
| 94 | + @override |
| 95 | + EdgeInsetsGeometry get expandedTitlePadding => const EdgeInsets.fromLTRB(16, 0, 16, 20); |
| 96 | +} |
| 97 | +
|
| 98 | +class _LargeScrollUnderFlexibleConfig with _ScrollUnderFlexibleConfig { |
| 99 | + _LargeScrollUnderFlexibleConfig(this.context); |
| 100 | +
|
| 101 | + final BuildContext context; |
| 102 | + late final ThemeData _theme = Theme.of(context); |
| 103 | + late final ColorScheme _colors = _theme.colorScheme; |
| 104 | + late final TextTheme _textTheme = _theme.textTheme; |
| 105 | +
|
| 106 | + static const double collapsedHeight = ${number(TokenAppBarSmall.containerHeight)}; |
| 107 | + static const double expandedHeight = ${number(TokenAppBarLarge.containerHeight)}; |
| 108 | +
|
| 109 | + @override |
| 110 | + TextStyle? get collapsedTextStyle => |
| 111 | + _textTheme.titleLarge?.apply(color: ${color(TokenAppBar.titleColor, '_colors')}); |
| 112 | +
|
| 113 | + @override |
| 114 | + TextStyle? get expandedTextStyle => |
| 115 | + _textTheme.headlineMedium?.apply(color: ${color(TokenAppBar.titleColor, '_colors')}); |
| 116 | +
|
| 117 | + @override |
| 118 | + EdgeInsetsGeometry get expandedTitlePadding => const EdgeInsets.fromLTRB(16, 0, 16, 28); |
| 119 | +} |
| 120 | +'''; |
| 121 | +} |
0 commit comments