Unverified Commit 9a8e2f0c authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Validate style in TextField (#24587)

* Validate style in TextField

* Fix analyze problems

* Use assert and move to top

* Simplified assertion
parent 4a110b62
......@@ -568,6 +568,12 @@ class _TextFieldState extends State<TextField> 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;
......
......@@ -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);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment