diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index a3c505b136..8293369de3 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -568,6 +568,12 @@ class _TextFieldState extends State with AutomaticKeepAliveClientMixi // TODO(jonahwilliams): uncomment out this check once we have migrated tests. // assert(debugCheckHasMaterialLocalizations(context)); assert(debugCheckHasDirectionality(context)); + assert( + !(widget.style != null && widget.style.inherit == false && + (widget.style.fontSize == null || widget.style.textBaseline == null)), + 'inherit false style must supply fontSize and textBaseline', + ); + final ThemeData themeData = Theme.of(context); final TextStyle style = widget.style ?? themeData.textTheme.subhead; final Brightness keyboardAppearance = widget.keyboardAppearance ?? themeData.primaryColorBrightness; diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 6e37dd2a26..75526ea66e 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -3419,4 +3419,35 @@ void main() { await tester.tap(find.byType(TextField)); expect(tapCount, 0); }); + + testWidgets('style enforces required fields', (WidgetTester tester) async { + Widget buildFrame(TextStyle style) { + return MaterialApp( + home: Material( + child: TextField( + style: style, + ), + ), + ); + } + + await tester.pumpWidget(buildFrame(const TextStyle( + inherit: false, + fontSize: 12.0, + textBaseline: TextBaseline.alphabetic, + ))); + expect(tester.takeException(), isNull); + + // With inherit not set to false, will pickup required fields from theme + await tester.pumpWidget(buildFrame(const TextStyle( + fontSize: 12.0, + ))); + expect(tester.takeException(), isNull); + + await tester.pumpWidget(buildFrame(const TextStyle( + inherit: false, + fontSize: 12.0, + ))); + expect(tester.takeException(), isNotNull); + }); }