@@ -21,6 +21,16 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
21
21
late final ColorScheme _colors = Theme.of(context).colorScheme;
22
22
late final TextTheme _textTheme = Theme.of(context).textTheme;
23
23
24
+ // For InputDecorator, focused state should take precedence over hovered state.
25
+ // For instance, the focused state increases border width (2dp) and applies bright
26
+ // colors (primary color or error color) while the hovered state has the same border
27
+ // than the non-focused state (1dp) and uses a color a little darker than non-focused
28
+ // state. On desktop, it is also very common that a text field is focused and hovered
29
+ // because users often rely on mouse selection.
30
+ // For other widgets, hovered state takes precedence over focused state, because it
31
+ // is mainly used to determine the overlay color,
32
+ // see https://github.com/flutter/flutter/pull/125905.
33
+
24
34
@override
25
35
TextStyle? get hintStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
26
36
if (states.contains(MaterialState.disabled)) {
@@ -139,20 +149,20 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
139
149
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.disabled.label-text' )});
140
150
}
141
151
if (states.contains(MaterialState.error)) {
142
- if (states.contains(MaterialState.hovered)) {
143
- return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.hover.label-text' )});
144
- }
145
152
if (states.contains(MaterialState.focused)) {
146
153
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.focus.label-text' )});
147
154
}
155
+ if (states.contains(MaterialState.hovered)) {
156
+ return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.hover.label-text' )});
157
+ }
148
158
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.label-text' )});
149
159
}
150
- if (states.contains(MaterialState.hovered)) {
151
- return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.hover.label-text' )});
152
- }
153
160
if (states.contains(MaterialState.focused)) {
154
161
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.focus.label-text' )});
155
162
}
163
+ if (states.contains(MaterialState.hovered)) {
164
+ return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.hover.label-text' )});
165
+ }
156
166
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.label-text' )});
157
167
});
158
168
@@ -163,20 +173,20 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
163
173
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.disabled.label-text' )});
164
174
}
165
175
if (states.contains(MaterialState.error)) {
166
- if (states.contains(MaterialState.hovered)) {
167
- return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.hover.label-text' )});
168
- }
169
176
if (states.contains(MaterialState.focused)) {
170
177
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.focus.label-text' )});
171
178
}
179
+ if (states.contains(MaterialState.hovered)) {
180
+ return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.hover.label-text' )});
181
+ }
172
182
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.label-text' )});
173
183
}
174
- if (states.contains(MaterialState.hovered)) {
175
- return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.hover.label-text' )});
176
- }
177
184
if (states.contains(MaterialState.focused)) {
178
185
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.focus.label-text' )});
179
186
}
187
+ if (states.contains(MaterialState.hovered)) {
188
+ return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.hover.label-text' )});
189
+ }
180
190
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.label-text' )});
181
191
});
182
192
@@ -185,24 +195,24 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
185
195
final TextStyle textStyle = ${textStyle ("md.comp.filled-text-field.supporting-text" )} ?? const TextStyle();
186
196
if (states.contains(MaterialState.disabled)) {
187
197
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.disabled.supporting-text' )});
188
- }${componentColor ('md.comp.filled-text-field.hover.supporting-text' ) == componentColor ('md.comp.filled-text-field.supporting-text' ) ? '' : '''
189
- if (states.contains(MaterialState.hovered)) {
190
- return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.hover.supporting-text' )});
191
- }''' }${componentColor ('md.comp.filled-text-field.focus.supporting-text' ) == componentColor ('md.comp.filled-text-field.supporting-text' ) ? '' : '''
198
+ }${componentColor ('md.comp.filled-text-field.focus.supporting-text' ) == componentColor ('md.comp.filled-text-field.supporting-text' ) ? '' : '''
192
199
if (states.contains(MaterialState.focused)) {
193
200
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.focus.supporting-text' )});
201
+ }''' }${componentColor ('md.comp.filled-text-field.hover.supporting-text' ) == componentColor ('md.comp.filled-text-field.supporting-text' ) ? '' : '''
202
+ if (states.contains(MaterialState.hovered)) {
203
+ return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.hover.supporting-text' )});
194
204
}''' }
195
205
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.supporting-text' )});
196
206
});
197
207
198
208
@override
199
209
TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
200
210
final TextStyle textStyle = ${textStyle ("md.comp.filled-text-field.supporting-text" )} ?? const TextStyle();${componentColor ('md.comp.filled-text-field.error.hover.supporting-text' ) == componentColor ('md.comp.filled-text-field.error.supporting-text' ) ? '' : '''
201
- if (states.contains(MaterialState.hovered)) {
202
- return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.hover.supporting-text' )});
203
- }''' }${componentColor ('md.comp.filled-text-field.error.focus.supporting-text' ) == componentColor ('md.comp.filled-text-field.error.supporting-text' ) ? '' : '''
204
211
if (states.contains(MaterialState.focused)) {
205
212
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.focus.supporting-text' )});
213
+ }''' }${componentColor ('md.comp.filled-text-field.error.focus.supporting-text' ) == componentColor ('md.comp.filled-text-field.error.supporting-text' ) ? '' : '''
214
+ if (states.contains(MaterialState.hovered)) {
215
+ return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.hover.supporting-text' )});
206
216
}''' }
207
217
return textStyle.copyWith(color: ${componentColor ('md.comp.filled-text-field.error.supporting-text' )});
208
218
});
0 commit comments