From fdca33c5b115e76073373326cbd15bdff4839650 Mon Sep 17 00:00:00 2001 From: Bruno Leroux Date: Tue, 28 May 2024 20:27:55 +0200 Subject: [PATCH] fix M2 InputDecorator suffix icon doesn't turn red on error (#149161) The suffixIcon of a TextField with an error now turns red like it should (on Material 2). --- .../lib/src/material/input_decorator.dart | 7 ++++-- .../test/material/input_decorator_test.dart | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index f69ef7a9aa3..1e2642533ee 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -4570,7 +4570,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme { @override TextStyle? get helperStyle => MaterialStateTextStyle.resolveWith((Set states) { - final ThemeData themeData= Theme.of(context); + final ThemeData themeData = Theme.of(context); if (states.contains(MaterialState.disabled)) { return themeData.textTheme.bodySmall!.copyWith(color: Colors.transparent); } @@ -4580,7 +4580,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme { @override TextStyle? get errorStyle => MaterialStateTextStyle.resolveWith((Set states) { - final ThemeData themeData= Theme.of(context); + final ThemeData themeData = Theme.of(context); if (states.contains(MaterialState.disabled)) { return themeData.textTheme.bodySmall!.copyWith(color: Colors.transparent); } @@ -4630,6 +4630,9 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme { if (states.contains(MaterialState.disabled) && !states.contains(MaterialState.focused)) { return Theme.of(context).disabledColor; } + if (states.contains(MaterialState.error)) { + return Theme.of(context).colorScheme.error; + } if (states.contains(MaterialState.focused)) { return Theme.of(context).colorScheme.primary; } diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 8e409752533..9c605408d92 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -8885,6 +8885,29 @@ void main() { expect(tester.getTopRight(find.text('text')).dx, lessThanOrEqualTo(tester.getTopLeft(find.byIcon(Icons.satellite)).dx)); }); + testWidgets('Material2 - InputDecorator suffixIcon color in error state', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + theme: ThemeData(useMaterial3: false), + home: Material( + child: TextField( + decoration: InputDecoration( + suffixIcon: IconButton( + icon: const Icon(Icons.close), + onPressed: () {}, + ), + errorText: 'Error state', + filled: true, + ), + ), + ), + ), + ); + + final ThemeData theme = Theme.of(tester.element(find.byType(TextField))); + expect(getIconStyle(tester, Icons.close)?.color, theme.colorScheme.error); + }); + testWidgets('InputDecorator prefixIconConstraints/suffixIconConstraints', (WidgetTester tester) async { await tester.pumpWidget( buildInputDecoratorM2(