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