Add M3 support for iconbuttons in error state in TextFields (#119925)
* add m3 iconbutton override * changes * spring cleaning * whitespace fix * sneaky whitespaces
This commit is contained in:
@@ -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<InputDecorator> 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<InputDecorator> 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,
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user