|
| 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 InputDecoratorTemplate extends TokenTemplate { |
| 8 | + const InputDecoratorTemplate(super.blockName, super.fileName, super.tokens, { |
| 9 | + super.colorSchemePrefix = '_colors.', |
| 10 | + super.textThemePrefix = '_textTheme.' |
| 11 | + }); |
| 12 | + |
| 13 | + @override |
| 14 | + String generate() => ''' |
| 15 | +// Generated version ${tokens["version"]} |
| 16 | +class _${blockName}DefaultsM3 extends InputDecorationTheme { |
| 17 | + _${blockName}DefaultsM3(this.context) |
| 18 | + : super(); |
| 19 | +
|
| 20 | + final BuildContext context; |
| 21 | +
|
| 22 | + late final ColorScheme _colors = Theme.of(context).colorScheme; |
| 23 | + late final TextTheme _textTheme = Theme.of(context).textTheme; |
| 24 | +
|
| 25 | + @override |
| 26 | + TextStyle? get hintStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { |
| 27 | + if (states.contains(MaterialState.disabled)) { |
| 28 | + return TextStyle(color: Theme.of(context).disabledColor); |
| 29 | + } |
| 30 | + return TextStyle(color: Theme.of(context).hintColor); |
| 31 | + }); |
| 32 | +
|
| 33 | + @override |
| 34 | + Color? get fillColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { |
| 35 | + if (states.contains(MaterialState.disabled)) { |
| 36 | + return ${componentColor("md.comp.filled-text-field.disabled.container")}; |
| 37 | + } |
| 38 | + return ${componentColor("md.comp.filled-text-field.container")}; |
| 39 | + }); |
| 40 | +
|
| 41 | + @override |
| 42 | + BorderSide? get activeIndicatorBorder => MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { |
| 43 | + if (states.contains(MaterialState.error)) { |
| 44 | + if (states.contains(MaterialState.hovered)) { |
| 45 | + return ${border('md.comp.filled-text-field.error.hover.active-indicator')}; |
| 46 | + } |
| 47 | + if (states.contains(MaterialState.focused)) { |
| 48 | + return ${border('md.comp.filled-text-field.error.focus.active-indicator')}; |
| 49 | + } |
| 50 | + return ${border('md.comp.filled-text-field.error.active-indicator')}; |
| 51 | + } |
| 52 | + if (states.contains(MaterialState.hovered)) { |
| 53 | + return ${border('md.comp.filled-text-field.hover.active-indicator')}; |
| 54 | + } |
| 55 | + if (states.contains(MaterialState.focused)) { |
| 56 | + return ${border('md.comp.filled-text-field.focus.active-indicator')}; |
| 57 | + } |
| 58 | + if (states.contains(MaterialState.disabled)) { |
| 59 | + return ${border('md.comp.filled-text-field.disabled.active-indicator')}; |
| 60 | + } |
| 61 | + return ${border('md.comp.filled-text-field.active-indicator')}; |
| 62 | + }); |
| 63 | +
|
| 64 | + @override |
| 65 | + BorderSide? get outlineBorder => MaterialStateBorderSide.resolveWith((Set<MaterialState> states) { |
| 66 | + if (states.contains(MaterialState.error)) { |
| 67 | + if (states.contains(MaterialState.hovered)) { |
| 68 | + return ${border('md.comp.outlined-text-field.error.hover.outline')}; |
| 69 | + } |
| 70 | + if (states.contains(MaterialState.focused)) { |
| 71 | + return ${border('md.comp.outlined-text-field.error.focus.outline')}; |
| 72 | + } |
| 73 | + return ${border('md.comp.outlined-text-field.error.outline')}; |
| 74 | + } |
| 75 | + if (states.contains(MaterialState.hovered)) { |
| 76 | + return ${border('md.comp.outlined-text-field.hover.outline')}; |
| 77 | + } |
| 78 | + if (states.contains(MaterialState.focused)) { |
| 79 | + return ${border('md.comp.outlined-text-field.focus.outline')}; |
| 80 | + } |
| 81 | + if (states.contains(MaterialState.disabled)) { |
| 82 | + return ${border('md.comp.outlined-text-field.disabled.outline')}; |
| 83 | + } |
| 84 | + return ${border('md.comp.outlined-text-field.outline')}; |
| 85 | + }); |
| 86 | +
|
| 87 | + @override |
| 88 | + Color? get iconColor => ${componentColor("md.comp.filled-text-field.leading-icon")}; |
| 89 | +
|
| 90 | + @override |
| 91 | + Color? get prefixIconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { |
| 92 | + if(states.contains(MaterialState.error)) { |
| 93 | + if (states.contains(MaterialState.hovered)) { |
| 94 | + return ${componentColor('md.comp.filled-text-field.error.hover.leading-icon')}; |
| 95 | + } |
| 96 | + if (states.contains(MaterialState.focused)) { |
| 97 | + return ${componentColor('md.comp.filled-text-field.error.focus.leading-icon')}; |
| 98 | + } |
| 99 | + return ${componentColor('md.comp.filled-text-field.error.leading-icon')}; |
| 100 | + } |
| 101 | + if (states.contains(MaterialState.hovered)) { |
| 102 | + return ${componentColor('md.comp.filled-text-field.hover.leading-icon')}; |
| 103 | + } |
| 104 | + if (states.contains(MaterialState.focused)) { |
| 105 | + return ${componentColor('md.comp.filled-text-field.focus.leading-icon')}; |
| 106 | + } |
| 107 | + if (states.contains(MaterialState.disabled)) { |
| 108 | + return ${componentColor('md.comp.filled-text-field.disabled.leading-icon')}; |
| 109 | + } |
| 110 | + return ${componentColor('md.comp.filled-text-field.leading-icon')}; |
| 111 | + }); |
| 112 | +
|
| 113 | + @override |
| 114 | + Color? get suffixIconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) { |
| 115 | + if(states.contains(MaterialState.error)) { |
| 116 | + if (states.contains(MaterialState.hovered)) { |
| 117 | + return ${componentColor('md.comp.filled-text-field.error.hover.trailing-icon')}; |
| 118 | + } |
| 119 | + if (states.contains(MaterialState.focused)) { |
| 120 | + return ${componentColor('md.comp.filled-text-field.error.focus.trailing-icon')}; |
| 121 | + } |
| 122 | + return ${componentColor('md.comp.filled-text-field.error.trailing-icon')}; |
| 123 | + } |
| 124 | + if (states.contains(MaterialState.hovered)) { |
| 125 | + return ${componentColor('md.comp.filled-text-field.hover.trailing-icon')}; |
| 126 | + } |
| 127 | + if (states.contains(MaterialState.focused)) { |
| 128 | + return ${componentColor('md.comp.filled-text-field.focus.trailing-icon')}; |
| 129 | + } |
| 130 | + if (states.contains(MaterialState.disabled)) { |
| 131 | + return ${componentColor('md.comp.filled-text-field.disabled.trailing-icon')}; |
| 132 | + } |
| 133 | + return ${componentColor('md.comp.filled-text-field.trailing-icon')}; |
| 134 | + }); |
| 135 | +
|
| 136 | + @override |
| 137 | + TextStyle? get labelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { |
| 138 | + final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle(); |
| 139 | + if(states.contains(MaterialState.error)) { |
| 140 | + if (states.contains(MaterialState.hovered)) { |
| 141 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.hover.label-text')}); |
| 142 | + } |
| 143 | + if (states.contains(MaterialState.focused)) { |
| 144 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.focus.label-text')}); |
| 145 | + } |
| 146 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.label-text')}); |
| 147 | + } |
| 148 | + if (states.contains(MaterialState.hovered)) { |
| 149 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.hover.label-text')}); |
| 150 | + } |
| 151 | + if (states.contains(MaterialState.focused)) { |
| 152 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.focus.label-text')}); |
| 153 | + } |
| 154 | + if (states.contains(MaterialState.disabled)) { |
| 155 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.disabled.label-text')}); |
| 156 | + } |
| 157 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.label-text')}); |
| 158 | + }); |
| 159 | +
|
| 160 | + @override |
| 161 | + TextStyle? get floatingLabelStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { |
| 162 | + final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.label-text")} ?? const TextStyle(); |
| 163 | + if(states.contains(MaterialState.error)) { |
| 164 | + if (states.contains(MaterialState.hovered)) { |
| 165 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.hover.label-text')}); |
| 166 | + } |
| 167 | + if (states.contains(MaterialState.focused)) { |
| 168 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.focus.label-text')}); |
| 169 | + } |
| 170 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.label-text')}); |
| 171 | + } |
| 172 | + if (states.contains(MaterialState.hovered)) { |
| 173 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.hover.label-text')}); |
| 174 | + } |
| 175 | + if (states.contains(MaterialState.focused)) { |
| 176 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.focus.label-text')}); |
| 177 | + } |
| 178 | + if (states.contains(MaterialState.disabled)) { |
| 179 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.disabled.label-text')}); |
| 180 | + } |
| 181 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.label-text')}); |
| 182 | + }); |
| 183 | +
|
| 184 | + @override |
| 185 | + TextStyle? get helperStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { |
| 186 | + final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.supporting-text")} ?? const TextStyle(); |
| 187 | + if (states.contains(MaterialState.hovered)) { |
| 188 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.hover.supporting-text')}); |
| 189 | + } |
| 190 | + if (states.contains(MaterialState.focused)) { |
| 191 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.focus.supporting-text')}); |
| 192 | + } |
| 193 | + if (states.contains(MaterialState.disabled)) { |
| 194 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.disabled.supporting-text')}); |
| 195 | + } |
| 196 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.supporting-text')}); |
| 197 | + }); |
| 198 | +
|
| 199 | + @override |
| 200 | + TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) { |
| 201 | + final TextStyle textStyle= ${textStyle("md.comp.filled-text-field.supporting-text")} ?? const TextStyle(); |
| 202 | + if (states.contains(MaterialState.hovered)) { |
| 203 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.hover.supporting-text')}); |
| 204 | + } |
| 205 | + if (states.contains(MaterialState.focused)) { |
| 206 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.focus.supporting-text')}); |
| 207 | + } |
| 208 | + return textStyle.copyWith(color:${componentColor('md.comp.filled-text-field.error.supporting-text')}); |
| 209 | + }); |
| 210 | +} |
| 211 | +'''; |
| 212 | +} |
0 commit comments