Validate style in TextField (#24587)
* Validate style in TextField * Fix analyze problems * Use assert and move to top * Simplified assertion
This commit is contained in:
parent
4a110b6227
commit
9a8e2f0c4b
@ -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);
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user