Skip to content

Commit fdca33c

Browse files
authored
fix M2 InputDecorator suffix icon doesn't turn red on error (flutter#149161)
The suffixIcon of a TextField with an error now turns red like it should (on Material 2).
1 parent e2e68c0 commit fdca33c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4570,7 +4570,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme {
45704570

45714571
@override
45724572
TextStyle? get helperStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
4573-
final ThemeData themeData= Theme.of(context);
4573+
final ThemeData themeData = Theme.of(context);
45744574
if (states.contains(MaterialState.disabled)) {
45754575
return themeData.textTheme.bodySmall!.copyWith(color: Colors.transparent);
45764576
}
@@ -4580,7 +4580,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme {
45804580

45814581
@override
45824582
TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
4583-
final ThemeData themeData= Theme.of(context);
4583+
final ThemeData themeData = Theme.of(context);
45844584
if (states.contains(MaterialState.disabled)) {
45854585
return themeData.textTheme.bodySmall!.copyWith(color: Colors.transparent);
45864586
}
@@ -4630,6 +4630,9 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme {
46304630
if (states.contains(MaterialState.disabled) && !states.contains(MaterialState.focused)) {
46314631
return Theme.of(context).disabledColor;
46324632
}
4633+
if (states.contains(MaterialState.error)) {
4634+
return Theme.of(context).colorScheme.error;
4635+
}
46334636
if (states.contains(MaterialState.focused)) {
46344637
return Theme.of(context).colorScheme.primary;
46354638
}

packages/flutter/test/material/input_decorator_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8885,6 +8885,29 @@ void main() {
88858885
expect(tester.getTopRight(find.text('text')).dx, lessThanOrEqualTo(tester.getTopLeft(find.byIcon(Icons.satellite)).dx));
88868886
});
88878887

8888+
testWidgets('Material2 - InputDecorator suffixIcon color in error state', (WidgetTester tester) async {
8889+
await tester.pumpWidget(
8890+
MaterialApp(
8891+
theme: ThemeData(useMaterial3: false),
8892+
home: Material(
8893+
child: TextField(
8894+
decoration: InputDecoration(
8895+
suffixIcon: IconButton(
8896+
icon: const Icon(Icons.close),
8897+
onPressed: () {},
8898+
),
8899+
errorText: 'Error state',
8900+
filled: true,
8901+
),
8902+
),
8903+
),
8904+
),
8905+
);
8906+
8907+
final ThemeData theme = Theme.of(tester.element(find.byType(TextField)));
8908+
expect(getIconStyle(tester, Icons.close)?.color, theme.colorScheme.error);
8909+
});
8910+
88888911
testWidgets('InputDecorator prefixIconConstraints/suffixIconConstraints', (WidgetTester tester) async {
88898912
await tester.pumpWidget(
88908913
buildInputDecoratorM2(

0 commit comments

Comments
 (0)