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
This commit is contained in:
Renzo Olivares 2024-01-18 09:37:06 -08:00 committed by GitHub
parent 3123d98132
commit cd06ba7ab6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View file

@ -1000,7 +1000,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
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() {
final MaterialLocalizations localizations = MaterialLocalizations.of(context);

View file

@ -14966,6 +14966,31 @@ void main() {
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', () {
const int maxLength = 5;