diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 74cf19e131..6a38769d19 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -12,6 +12,8 @@ import 'package:flutter/widgets.dart'; import 'color_scheme.dart'; import 'colors.dart'; import 'constants.dart'; +import 'icon_button.dart'; +import 'icon_button_theme.dart'; import 'input_border.dart'; import 'material.dart'; import 'material_state.dart'; @@ -2307,19 +2309,27 @@ class _InputDecoratorState extends State with TickerProviderStat cursor: SystemMouseCursors.basic, child: ConstrainedBox( constraints: decoration.prefixIconConstraints ?? - themeData.visualDensity.effectiveConstraints( - const BoxConstraints( - minWidth: kMinInteractiveDimension, - minHeight: kMinInteractiveDimension, - ), + themeData.visualDensity.effectiveConstraints( + const BoxConstraints( + minWidth: kMinInteractiveDimension, + minHeight: kMinInteractiveDimension, ), + ), child: IconTheme.merge( data: IconThemeData( color: _getPrefixIconColor(themeData, defaults), size: iconSize, ), - child: Semantics( - child: decoration.prefixIcon, + child: IconButtonTheme( + data: IconButtonThemeData( + style: IconButton.styleFrom( + foregroundColor: _getPrefixIconColor(themeData, defaults), + iconSize: iconSize, + ), + ), + child: Semantics( + child: decoration.prefixIcon, + ), ), ), ), @@ -2334,24 +2344,32 @@ class _InputDecoratorState extends State with TickerProviderStat cursor: SystemMouseCursors.basic, child: ConstrainedBox( constraints: decoration.suffixIconConstraints ?? - themeData.visualDensity.effectiveConstraints( - const BoxConstraints( - minWidth: kMinInteractiveDimension, - minHeight: kMinInteractiveDimension, + themeData.visualDensity.effectiveConstraints( + const BoxConstraints( + minWidth: kMinInteractiveDimension, + minHeight: kMinInteractiveDimension, + ), + ), + child: IconTheme.merge( + data: IconThemeData( + color: _getSuffixIconColor(themeData, defaults), + size: iconSize, + ), + child: IconButtonTheme( + data: IconButtonThemeData( + style: IconButton.styleFrom( + foregroundColor: _getSuffixIconColor(themeData, defaults), + iconSize: iconSize, + ), + ), + child: Semantics( + child: decoration.suffixIcon, ), ), - child: IconTheme.merge( - data: IconThemeData( - color: _getSuffixIconColor(themeData, defaults), - size: iconSize, - ), - child: Semantics( - child: decoration.suffixIcon, ), ), ), - ), - ); + ); final Widget helperError = _HelperError( textAlign: textAlign, diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 1484fe41bc..887b6986ae 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -148,6 +148,13 @@ double getOpacity(WidgetTester tester, String textValue) { return opacityWidget.opacity.value; } +TextStyle? getIconStyle(WidgetTester tester, IconData icon) { + final RichText iconRichText = tester.widget( + find.descendant(of: find.byIcon(icon), matching: find.byType(RichText)), + ); + return iconRichText.text.style; +} + void main() { for(final bool useMaterial3 in [true, false]){ testWidgets('InputDecorator input/label text layout', (WidgetTester tester) async { @@ -1732,6 +1739,33 @@ void main() { expect(tester.widget(find.widgetWithIcon(IconTheme,Icons.close).first).data.color, Colors.red); }); + testWidgets('InputDecorator suffixIconColor in M3 error state', (WidgetTester tester) async { + final ThemeData theme = ThemeData( + useMaterial3: true, + iconButtonTheme: const IconButtonThemeData( + style: ButtonStyle( + foregroundColor: MaterialStatePropertyAll(Colors.blue), + ), + ), + ); + await tester.pumpWidget( + MaterialApp( + theme: theme, + home: Material( + child: TextField( + decoration: InputDecoration( + suffixIcon: IconButton(icon: const Icon(Icons.close), onPressed: () {}), + errorText: 'error state', + filled: true, + ), + ), + ), + ), + ); + + expect(getIconStyle(tester, Icons.close)?.color, theme.colorScheme.error); + }); + testWidgets('InputDecorator prefix/suffix widgets', (WidgetTester tester) async { const Key pKey = Key('p'); const Key sKey = Key('s');