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 SearchBarTemplate extends TokenTemplate { |
8 | const SearchBarTemplate( |
9 | super.blockName, |
10 | super.fileName, |
11 | super.tokens, { |
12 | super.colorSchemePrefix = '_colors.' , |
13 | super.textThemePrefix = '_textTheme.' , |
14 | }); |
15 | |
16 | String _surfaceTint() { |
17 | final String? color = colorOrTransparent( |
18 | 'md.comp.search-bar.container.surface-tint-layer.color' , |
19 | ); |
20 | final String surfaceTintColor = 'MaterialStatePropertyAll<Color>( $color);' ; |
21 | if (color == 'Colors.transparent' ) { |
22 | return 'const $surfaceTintColor' ; |
23 | } |
24 | return surfaceTintColor; |
25 | } |
26 | |
27 | @override |
28 | String generate() => |
29 | ''' |
30 | class _SearchBarDefaultsM3 extends SearchBarThemeData { |
31 | _SearchBarDefaultsM3(this.context); |
32 | |
33 | final BuildContext context; |
34 | late final ColorScheme _colors = Theme.of(context).colorScheme; |
35 | late final TextTheme _textTheme = Theme.of(context).textTheme; |
36 | |
37 | @override |
38 | MaterialStateProperty<Color?>? get backgroundColor => |
39 | MaterialStatePropertyAll<Color>( ${componentColor("md.comp.search-bar.container" )}); |
40 | |
41 | @override |
42 | MaterialStateProperty<double>? get elevation => |
43 | const MaterialStatePropertyAll<double>( ${elevation("md.comp.search-bar.container" )}); |
44 | |
45 | @override |
46 | MaterialStateProperty<Color>? get shadowColor => |
47 | MaterialStatePropertyAll<Color>(_colors.shadow); |
48 | |
49 | @override |
50 | MaterialStateProperty<Color>? get surfaceTintColor => |
51 | ${_surfaceTint()} |
52 | |
53 | @override |
54 | MaterialStateProperty<Color?>? get overlayColor => |
55 | MaterialStateProperty.resolveWith((Set<MaterialState> states) { |
56 | if (states.contains(MaterialState.pressed)) { |
57 | return ${componentColor("md.comp.search-bar.pressed.state-layer" )}; |
58 | } |
59 | if (states.contains(MaterialState.hovered)) { |
60 | return ${componentColor("md.comp.search-bar.hover.state-layer" )}; |
61 | } |
62 | if (states.contains(MaterialState.focused)) { |
63 | return ${colorOrTransparent("md.comp.search-bar.focused.state-layer" )}; |
64 | } |
65 | return Colors.transparent; |
66 | }); |
67 | |
68 | // No default side |
69 | |
70 | @override |
71 | MaterialStateProperty<OutlinedBorder>? get shape => |
72 | const MaterialStatePropertyAll<OutlinedBorder>( ${shape('md.comp.search-bar.container' , '' )}); |
73 | |
74 | @override |
75 | MaterialStateProperty<EdgeInsetsGeometry>? get padding => |
76 | const MaterialStatePropertyAll<EdgeInsetsGeometry>(EdgeInsets.symmetric(horizontal: 8.0)); |
77 | |
78 | @override |
79 | MaterialStateProperty<TextStyle?> get textStyle => |
80 | MaterialStatePropertyAll<TextStyle?>( ${textStyleWithColor('md.comp.search-bar.input-text' )}); |
81 | |
82 | @override |
83 | MaterialStateProperty<TextStyle?> get hintStyle => |
84 | MaterialStatePropertyAll<TextStyle?>( ${textStyleWithColor('md.comp.search-bar.supporting-text' )}); |
85 | |
86 | @override |
87 | BoxConstraints get constraints => |
88 | const BoxConstraints(minWidth: 360.0, maxWidth: 800.0, minHeight: ${getToken('md.comp.search-bar.container.height' )}); |
89 | |
90 | @override |
91 | TextCapitalization get textCapitalization => TextCapitalization.none; |
92 | } |
93 | ''' ; |
94 | } |
95 | |