Skip to content

Commit e02d29d

Browse files
authored
Fix InputDecorator.prefixIcon color when disabled (#149595)
## Description This PRs makes the `InputDecoration.prefixIcon` color compliant with the M3 spec. From M3 spec, the color should be `onSurface.withOpacity(0.38)`, see https://m3.material.io/components/text-fields/specs#e4964192-72ad-414f-85b4-4b4357abb83c ![image](https://github.com/flutter/flutter/assets/840911/298d9aaf-fcda-479a-a8dd-0ee84db98242) ## Related Issue Fixes flutter/flutter#149411. ## Tests Updates 2 tests.
1 parent a92318d commit e02d29d

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

dev/tools/gen_defaults/generated/used_tokens.csv

+2
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ md.comp.filled-text-field.disabled.container.color,
238238
md.comp.filled-text-field.disabled.container.opacity,
239239
md.comp.filled-text-field.disabled.label-text.color,
240240
md.comp.filled-text-field.disabled.label-text.opacity,
241+
md.comp.filled-text-field.disabled.leading-icon.color,
242+
md.comp.filled-text-field.disabled.leading-icon.opacity,
241243
md.comp.filled-text-field.disabled.supporting-text.color,
242244
md.comp.filled-text-field.disabled.supporting-text.opacity,
243245
md.comp.filled-text-field.disabled.trailing-icon.color,

dev/tools/gen_defaults/lib/input_decorator_template.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ class _${blockName}DefaultsM3 extends InputDecorationTheme {
9797
Color? get iconColor => ${componentColor("md.comp.filled-text-field.leading-icon")};
9898
9999
@override
100-
Color? get prefixIconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) {${componentColor('md.comp.filled-text-field.error.leading-icon') == componentColor('md.comp.filled-text-field.leading-icon') ? '' : '''
100+
Color? get prefixIconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) {
101101
if (states.contains(MaterialState.disabled)) {
102102
return ${componentColor('md.comp.filled-text-field.disabled.leading-icon')};
103-
}
103+
}${componentColor('md.comp.filled-text-field.error.leading-icon') == componentColor('md.comp.filled-text-field.leading-icon') ? '' : '''
104104
if (states.contains(MaterialState.error)) {
105105
if (states.contains(MaterialState.hovered)) {
106106
return ${componentColor('md.comp.filled-text-field.error.hover.leading-icon')};

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

+3
Original file line numberDiff line numberDiff line change
@@ -4736,6 +4736,9 @@ class _InputDecoratorDefaultsM3 extends InputDecorationTheme {
47364736

47374737
@override
47384738
Color? get prefixIconColor => MaterialStateColor.resolveWith((Set<MaterialState> states) {
4739+
if (states.contains(MaterialState.disabled)) {
4740+
return _colors.onSurface.withOpacity(0.38);
4741+
}
47394742
return _colors.onSurfaceVariant;
47404743
});
47414744

packages/flutter/test/material/input_decorator_test.dart

+2-6
Original file line numberDiff line numberDiff line change
@@ -5443,9 +5443,7 @@ void main() {
54435443
);
54445444

54455445
final ThemeData theme = Theme.of(tester.element(findPrefixIcon()));
5446-
// TODO(bleroux): based on M3 spec, it should be theme.colorScheme.onSurface.withOpacity(0.38).
5447-
// See https://github.com/flutter/flutter/issues/149411.
5448-
final Color expectedColor = theme.colorScheme.onSurfaceVariant;
5446+
final Color expectedColor = theme.colorScheme.onSurface.withOpacity(0.38);
54495447
expect(getPrefixIconStyle(tester).color, expectedColor);
54505448
});
54515449

@@ -5921,9 +5919,7 @@ void main() {
59215919
);
59225920

59235921
final ThemeData theme = Theme.of(tester.element(findPrefixIcon()));
5924-
// TODO(bleroux): based on M3 spec, it should be theme.colorScheme.onSurface.withOpacity(0.38).
5925-
// See https://github.com/flutter/flutter/issues/149411.
5926-
final Color expectedColor = theme.colorScheme.onSurfaceVariant;
5922+
final Color expectedColor = theme.colorScheme.onSurface.withOpacity(0.38);
59275923
expect(getPrefixIconStyle(tester).color, expectedColor);
59285924
});
59295925

0 commit comments

Comments
 (0)