Skip to content

Commit 4608a89

Browse files
authored
Fix InputDecorator suffixIcon color when in error and hovered (#149643)
## Description This PRs makes the `InputDecoration.suffixIcon` color compliant with the M3 spec when in error state and hovered. From M3 spec, the color should be `onErrorContainer`, see https://m3.material.io/components/text-fields/specs#e4964192-72ad-414f-85b4-4b4357abb83c ![image](https://github.com/flutter/flutter/assets/840911/1d8d7bb6-608f-4783-aff5-2123392c4dc1) ## Related Issue Fixes flutter/flutter#149410. ## Tests Updates 2 tests.
1 parent c5025ad commit 4608a89

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

dev/tools/gen_defaults/generated/used_tokens.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ md.comp.filled-text-field.error.focus.trailing-icon.color,
252252
md.comp.filled-text-field.error.hover.active-indicator.color,
253253
md.comp.filled-text-field.error.hover.label-text.color,
254254
md.comp.filled-text-field.error.hover.supporting-text.color,
255+
md.comp.filled-text-field.error.hover.trailing-icon.color,
255256
md.comp.filled-text-field.error.label-text.color,
256257
md.comp.filled-text-field.error.leading-icon.color,
257258
md.comp.filled-text-field.error.supporting-text.color,

dev/tools/gen_defaults/lib/input_decorator_template.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
124124
if (states.contains(MaterialState.disabled)) {
125125
return ${componentColor('md.comp.filled-text-field.disabled.trailing-icon')};
126126
}
127-
if (states.contains(MaterialState.error)) {${componentColor('md.comp.filled-text-field.error.trailing-icon') == componentColor('md.comp.filled-text-field.error.focus.trailing-icon') ? '' : '''
127+
if (states.contains(MaterialState.error)) {
128128
if (states.contains(MaterialState.hovered)) {
129129
return ${componentColor('md.comp.filled-text-field.error.hover.trailing-icon')};
130-
}
130+
}${componentColor('md.comp.filled-text-field.error.trailing-icon') == componentColor('md.comp.filled-text-field.error.focus.trailing-icon') ? '' : '''
131131
if (states.contains(MaterialState.focused)) {
132132
return ${componentColor('md.comp.filled-text-field.error.focus.trailing-icon')};
133133
}'''}

packages/flutter/lib/src/material/input_decorator.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4748,6 +4748,9 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme {
47484748
return _colors.onSurface.withOpacity(0.38);
47494749
}
47504750
if (states.contains(MaterialState.error)) {
4751+
if (states.contains(MaterialState.hovered)) {
4752+
return _colors.onErrorContainer;
4753+
}
47514754
return _colors.error;
47524755
}
47534756
return _colors.onSurfaceVariant;

packages/flutter/test/material/input_decorator_test.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5786,9 +5786,7 @@ void main() {
57865786
);
57875787

57885788
final ThemeData theme = Theme.of(tester.element(findSuffixIcon()));
5789-
// TODO(bleroux): based on M3 spec, it should be theme.colorScheme.onErrorContainer.
5790-
// See https://github.com/flutter/flutter/issues/149410.
5791-
final Color expectedColor = theme.colorScheme.error;
5789+
final Color expectedColor = theme.colorScheme.onErrorContainer;
57925790
expect(getSuffixIconStyle(tester).color, expectedColor);
57935791
});
57945792
});
@@ -6262,9 +6260,7 @@ void main() {
62626260
);
62636261

62646262
final ThemeData theme = Theme.of(tester.element(findSuffixIcon()));
6265-
// TODO(bleroux): based on M3 spec, it should be theme.colorScheme.onErrorContainer.
6266-
// See https://github.com/flutter/flutter/issues/149410.
6267-
final Color expectedColor = theme.colorScheme.error;
6263+
final Color expectedColor = theme.colorScheme.onErrorContainer;
62686264
expect(getSuffixIconStyle(tester).color, expectedColor);
62696265
});
62706266
});

0 commit comments

Comments
 (0)