Unverified Commit c5e8757f authored by Eilidh Southren's avatar Eilidh Southren Committed by GitHub

Add M3 support for iconbuttons in error state in TextFields (#119925)

* add m3 iconbutton override

* changes

* spring cleaning

* whitespace fix

* sneaky whitespaces
parent e0b2138b
......@@ -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';
......@@ -2318,12 +2320,20 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
color: _getPrefixIconColor(themeData, defaults),
size: iconSize,
),
child: IconButtonTheme(
data: IconButtonThemeData(
style: IconButton.styleFrom(
foregroundColor: _getPrefixIconColor(themeData, defaults),
iconSize: iconSize,
),
),
child: Semantics(
child: decoration.prefixIcon,
),
),
),
),
),
);
final Widget? suffixIcon = decoration.suffixIcon == null ? null :
......@@ -2345,12 +2355,20 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
color: _getSuffixIconColor(themeData, defaults),
size: iconSize,
),
child: IconButtonTheme(
data: IconButtonThemeData(
style: IconButton.styleFrom(
foregroundColor: _getSuffixIconColor(themeData, defaults),
iconSize: iconSize,
),
),
child: Semantics(
child: decoration.suffixIcon,
),
),
),
),
),
);
final Widget helperError = _HelperError(
......
......@@ -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<RichText>(
find.descendant(of: find.byIcon(icon), matching: find.byType(RichText)),
);
return iconRichText.text.style;
}
void main() {
for(final bool useMaterial3 in <bool>[true, false]){
testWidgets('InputDecorator input/label text layout', (WidgetTester tester) async {
......@@ -1732,6 +1739,33 @@ void main() {
expect(tester.widget<IconTheme>(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<Color>(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');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment