Skip to content

Commit 0dc7383

Browse files
committed
Fix InputDecoration does not apply errorStyle to error
1 parent 7ec7baf commit 0dc7383

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/flutter/lib/src/material/input_decorator.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,11 @@ class _HelperErrorState extends State<_HelperError> with SingleTickerProviderSta
401401

402402
Widget _buildError() {
403403
assert(widget.error != null || widget.errorText != null);
404-
final Widget? capturedError = widget.error;
405404
final String? capturedErrorText = widget.errorText;
405+
Widget? capturedError = widget.error;
406+
if (capturedError != null && widget.errorStyle != null) {
407+
capturedError = DefaultTextStyle(style: widget.errorStyle!, child: capturedError);
408+
}
406409
return Builder(
407410
builder: (BuildContext context) {
408411
return Semantics(

packages/flutter/test/material/input_decorator_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6210,6 +6210,21 @@ void main() {
62106210
);
62116211
}, throwsAssertionError);
62126212
});
6213+
6214+
// Regression test for https://github.com/flutter/flutter/issues/174784.
6215+
testWidgets('InputDecorator error widget text style defaults to errorStyle', (
6216+
WidgetTester tester,
6217+
) async {
6218+
await tester.pumpWidget(
6219+
buildInputDecorator(decoration: const InputDecoration(error: Text(errorText))),
6220+
);
6221+
6222+
expect(findError(), findsOneWidget);
6223+
final ThemeData theme = Theme.of(tester.element(findDecorator()));
6224+
final Color expectedColor = theme.colorScheme.error;
6225+
final TextStyle expectedStyle = theme.textTheme.bodySmall!.copyWith(color: expectedColor);
6226+
expect(getErrorStyle(tester), expectedStyle);
6227+
});
62136228
});
62146229

62156230
testWidgets('InputDecorator with counter does not crash when given a 0 size', (

0 commit comments

Comments
 (0)