diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index e1942cd7f97..fb3b0bdf433 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -1000,7 +1000,7 @@ class _TextFieldState extends State 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); diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index e3f7de6fcf8..79323b47b21 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -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(find.byType(EditableText)); + expect(state.widget.cursorColor, Colors.green); + }); + group('MaxLengthEnforcement', () { const int maxLength = 5;