From 4608a8913767116234e95cb7d73a410e9a7a2fc9 Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Thu, 6 Jun 2024 08:11:25 +0200 Subject: [PATCH] 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 https://github.com/flutter/flutter/issues/149410. ## Tests Updates 2 tests. --- dev/tools/gen_defaults/generated/used_tokens.csv | 1 + dev/tools/gen_defaults/lib/input_decorator_template.dart | 4 ++-- packages/flutter/lib/src/material/input_decorator.dart | 3 +++ packages/flutter/test/material/input_decorator_test.dart | 8 ++------ 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dev/tools/gen_defaults/generated/used_tokens.csv b/dev/tools/gen_defaults/generated/used_tokens.csv index 87120d20dcc6..254ae1679344 100644 --- a/dev/tools/gen_defaults/generated/used_tokens.csv +++ b/dev/tools/gen_defaults/generated/used_tokens.csv @@ -252,6 +252,7 @@ md.comp.filled-text-field.error.focus.trailing-icon.color, md.comp.filled-text-field.error.hover.active-indicator.color, md.comp.filled-text-field.error.hover.label-text.color, md.comp.filled-text-field.error.hover.supporting-text.color, +md.comp.filled-text-field.error.hover.trailing-icon.color, md.comp.filled-text-field.error.label-text.color, md.comp.filled-text-field.error.leading-icon.color, md.comp.filled-text-field.error.supporting-text.color, diff --git a/dev/tools/gen_defaults/lib/input_decorator_template.dart b/dev/tools/gen_defaults/lib/input_decorator_template.dart index 3fb208b8fb70..80d67a0b8d6c 100644 --- a/dev/tools/gen_defaults/lib/input_decorator_template.dart +++ b/dev/tools/gen_defaults/lib/input_decorator_template.dart @@ -124,10 +124,10 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme { if (states.contains(MaterialState.disabled)) { return ${componentColor('md.comp.filled-text-field.disabled.trailing-icon')}; } - if (states.contains(MaterialState.error)) {${componentColor('md.comp.filled-text-field.error.trailing-icon') == componentColor('md.comp.filled-text-field.error.focus.trailing-icon') ? '' : ''' + if (states.contains(MaterialState.error)) { if (states.contains(MaterialState.hovered)) { return ${componentColor('md.comp.filled-text-field.error.hover.trailing-icon')}; - } + }${componentColor('md.comp.filled-text-field.error.trailing-icon') == componentColor('md.comp.filled-text-field.error.focus.trailing-icon') ? '' : ''' if (states.contains(MaterialState.focused)) { return ${componentColor('md.comp.filled-text-field.error.focus.trailing-icon')}; }'''} diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index c6730723581c..ad56f3e3ada1 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -4748,6 +4748,9 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme { return _colors.onSurface.withOpacity(0.38); } if (states.contains(MaterialState.error)) { + if (states.contains(MaterialState.hovered)) { + return _colors.onErrorContainer; + } return _colors.error; } return _colors.onSurfaceVariant; diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index c3fbe94d879c..91ca2f043588 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -5786,9 +5786,7 @@ void main() { ); final ThemeData theme = Theme.of(tester.element(findSuffixIcon())); - // TODO(bleroux): based on M3 spec, it should be theme.colorScheme.onErrorContainer. - // See https://github.com/flutter/flutter/issues/149410. - final Color expectedColor = theme.colorScheme.error; + final Color expectedColor = theme.colorScheme.onErrorContainer; expect(getSuffixIconStyle(tester).color, expectedColor); }); }); @@ -6262,9 +6260,7 @@ void main() { ); final ThemeData theme = Theme.of(tester.element(findSuffixIcon())); - // TODO(bleroux): based on M3 spec, it should be theme.colorScheme.onErrorContainer. - // See https://github.com/flutter/flutter/issues/149410. - final Color expectedColor = theme.colorScheme.error; + final Color expectedColor = theme.colorScheme.onErrorContainer; expect(getSuffixIconStyle(tester).color, expectedColor); }); });