Unverified Commit cd06ba7a authored by Renzo Olivares's avatar Renzo Olivares Committed by GitHub

Fix: TextField can inherit `errorStyle` from `InputDecorationTheme`. (#141227)

Previously `TextField`s error `cursorColor` was being derived without taking into account any `InputDecorationTheme` defaults. This change respects `InputDecorationTheme` defaults when deriving the error `cursorColor`.

Fixes #140607
parent 3123d981
...@@ -1000,7 +1000,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements ...@@ -1000,7 +1000,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
bool get _hasError => widget.decoration?.errorText != null || widget.decoration?.error != null || _hasIntrinsicError; bool get _hasError => widget.decoration?.errorText != null || widget.decoration?.error != null || _hasIntrinsicError;
Color get _errorColor => widget.cursorErrorColor ?? widget.decoration?.errorStyle?.color ?? Theme.of(context).colorScheme.error; Color get _errorColor => widget.cursorErrorColor ?? _getEffectiveDecoration().errorStyle?.color ?? Theme.of(context).colorScheme.error;
InputDecoration _getEffectiveDecoration() { InputDecoration _getEffectiveDecoration() {
final MaterialLocalizations localizations = MaterialLocalizations.of(context); final MaterialLocalizations localizations = MaterialLocalizations.of(context);
......
...@@ -14966,6 +14966,31 @@ void main() { ...@@ -14966,6 +14966,31 @@ void main() {
expect(tester.getTopLeft(find.text('Label')).dy, 12.0); expect(tester.getTopLeft(find.text('Label')).dy, 12.0);
}); });
// Regression test for https://github.com/flutter/flutter/issues/140607.
testWidgets('TextFields can inherit errorStyle color from InputDecorationTheme.', (WidgetTester tester) async {
Widget textFieldBuilder() {
return MaterialApp(
theme: ThemeData(
inputDecorationTheme: const InputDecorationTheme(
errorStyle: TextStyle(color: Colors.green),
),
),
home: const Scaffold(
body: TextField(
decoration: InputDecoration(
errorText: 'error',
),
),
),
);
}
await tester.pumpWidget(textFieldBuilder());
await tester.pumpAndSettle();
final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText));
expect(state.widget.cursorColor, Colors.green);
});
group('MaxLengthEnforcement', () { group('MaxLengthEnforcement', () {
const int maxLength = 5; const int maxLength = 5;
......
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