Unverified Commit 73e0dbf5 authored by Renzo Olivares's avatar Renzo Olivares Committed by GitHub

TextField should correctly resolve provided style for material states (#132330)

This change makes sure the style provided through the `TextField`s `style` parameter is resolved for material states before merging it with defaults.

Fixes #132212
parent 1e35d3a6
......@@ -1248,7 +1248,8 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
final ThemeData theme = Theme.of(context);
final DefaultSelectionStyle selectionStyle = DefaultSelectionStyle.of(context);
final TextStyle style = _getInputStyleForState(theme.useMaterial3 ? _m3InputStyle(context) : theme.textTheme.titleMedium!).merge(widget.style);
final TextStyle? providedStyle = MaterialStateProperty.resolveAs(widget.style, _materialState);
final TextStyle style = _getInputStyleForState(theme.useMaterial3 ? _m3InputStyle(context) : theme.textTheme.titleMedium!).merge(providedStyle);
final Brightness keyboardAppearance = widget.keyboardAppearance ?? theme.brightness;
final TextEditingController controller = _effectiveController;
final FocusNode focusNode = _effectiveFocusNode;
......
......@@ -6592,6 +6592,41 @@ void main() {
expect(editableText.style.color, theme.textTheme.bodyLarge!.color!.withOpacity(0.38));
});
testWidgets('Provided style correctly resolves for material states', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController(
text: 'Atwater Peel Sherbrooke Bonaventure',
);
final ThemeData theme = ThemeData.light(useMaterial3: true);
Widget buildFrame(bool enabled) {
return MaterialApp(
theme: theme,
home: Material(
child: Center(
child: TextField(
controller: controller,
enabled: enabled,
style: MaterialStateTextStyle.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return const TextStyle(color: Colors.red);
}
return const TextStyle(color: Colors.blue);
}),
),
),
),
);
}
await tester.pumpWidget(buildFrame(false));
EditableText editableText = tester.widget(find.byType(EditableText));
expect(editableText.style.color, Colors.red);
await tester.pumpWidget(buildFrame(true));
editableText = tester.widget(find.byType(EditableText));
expect(editableText.style.color, Colors.blue);
});
testWidgets('currentValueLength/maxValueLength are in the tree', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);
final TextEditingController controller = TextEditingController();
......
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