mirror of
https://github.com/flutter/flutter
synced 2024-10-12 11:12:54 +00:00
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:
parent
3123d98132
commit
cd06ba7ab6
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue