From 6a1fc9eae63375e460f868beeb8f32da6a2f774c Mon Sep 17 00:00:00 2001 From: hangyu Date: Tue, 23 Aug 2022 00:35:51 +0800 Subject: [PATCH] InputDecorator iconColor/prefixIconColor/suffixIconColor (#109988) --- .../lib/src/material/input_decorator.dart | 9 ++++--- .../test/material/input_decorator_test.dart | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index debcfd9c495..fd58da9baef 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -1991,17 +1991,20 @@ class _InputDecoratorState extends State with TickerProviderStat } Color _getIconColor(ThemeData themeData, InputDecorationTheme defaults) { - return MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.iconColor, materialState) + return MaterialStateProperty.resolveAs(decoration.iconColor, materialState) + ?? MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.iconColor, materialState) ?? MaterialStateProperty.resolveAs(defaults.iconColor!, materialState); } Color _getPrefixIconColor(ThemeData themeData, InputDecorationTheme defaults) { - return MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.prefixIconColor, materialState) + return MaterialStateProperty.resolveAs(decoration.prefixIconColor, materialState) + ?? MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.prefixIconColor, materialState) ?? MaterialStateProperty.resolveAs(defaults.prefixIconColor!, materialState); } Color _getSuffixIconColor(ThemeData themeData, InputDecorationTheme defaults) { - return MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.suffixIconColor, materialState) + return MaterialStateProperty.resolveAs(decoration.suffixIconColor, materialState) + ?? MaterialStateProperty.resolveAs(themeData.inputDecorationTheme.suffixIconColor, materialState) ?? MaterialStateProperty.resolveAs(defaults.suffixIconColor!, materialState); } diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index db2de05c6ee..14f8611e41f 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -1657,6 +1657,30 @@ void main() { expect(tester.getTopRight(find.text('text')).dx, lessThanOrEqualTo(tester.getTopLeft(find.text('s')).dx)); }); + testWidgets('InputDecorator iconColor/prefixIconColor/suffixIconColor', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Material( + child: TextField( + decoration: InputDecoration( + icon: Icon(Icons.cabin), + prefixIcon: Icon(Icons.sailing), + suffixIcon: Icon(Icons.close), + iconColor: Colors.amber, + prefixIconColor: Colors.green, + suffixIconColor: Colors.red, + filled: true, + ), + ), + ), + ), + ); + + expect(tester.widget(find.widgetWithIcon(IconTheme,Icons.cabin).first).data.color, Colors.amber); + expect(tester.widget(find.widgetWithIcon(IconTheme,Icons.sailing).first).data.color, Colors.green); + expect(tester.widget(find.widgetWithIcon(IconTheme,Icons.close).first).data.color, Colors.red); + }); + testWidgets('InputDecorator prefix/suffix widgets', (WidgetTester tester) async { const Key pKey = Key('p'); const Key sKey = Key('s');