mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
Text field style merge (#24449)
* Merge TextField style with global style so that style changes don't override unspecified fields * Test that a style param is merged with the theme * Test a few more style properties * Analysis fix
This commit is contained in:
parent
92efec3998
commit
952d24bf1e
|
@ -575,7 +575,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
|
|||
);
|
||||
|
||||
final ThemeData themeData = Theme.of(context);
|
||||
final TextStyle style = widget.style ?? themeData.textTheme.subhead;
|
||||
final TextStyle style = themeData.textTheme.subhead.merge(widget.style);
|
||||
final Brightness keyboardAppearance = widget.keyboardAppearance ?? themeData.primaryColorBrightness;
|
||||
final TextEditingController controller = _effectiveController;
|
||||
final FocusNode focusNode = _effectiveFocusNode;
|
||||
|
|
|
@ -3420,6 +3420,56 @@ void main() {
|
|||
expect(tapCount, 0);
|
||||
});
|
||||
|
||||
testWidgets('TextField style is merged with theme', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/23994
|
||||
|
||||
final ThemeData themeData = ThemeData(
|
||||
textTheme: TextTheme(
|
||||
subhead: TextStyle(
|
||||
color: Colors.blue[500],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Widget buildFrame(TextStyle style) {
|
||||
return MaterialApp(
|
||||
theme: themeData,
|
||||
home: Material(
|
||||
child: Center(
|
||||
child: TextField(
|
||||
style: style,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Empty TextStyle is overridden by theme
|
||||
await tester.pumpWidget(buildFrame(const TextStyle()));
|
||||
EditableText editableText = tester.widget(find.byType(EditableText));
|
||||
expect(editableText.style.color, themeData.textTheme.subhead.color);
|
||||
expect(editableText.style.background, themeData.textTheme.subhead.background);
|
||||
expect(editableText.style.shadows, themeData.textTheme.subhead.shadows);
|
||||
expect(editableText.style.decoration, themeData.textTheme.subhead.decoration);
|
||||
expect(editableText.style.locale, themeData.textTheme.subhead.locale);
|
||||
expect(editableText.style.wordSpacing, themeData.textTheme.subhead.wordSpacing);
|
||||
|
||||
// Properties set on TextStyle override theme
|
||||
const Color setColor = Colors.red;
|
||||
await tester.pumpWidget(buildFrame(const TextStyle(color: setColor)));
|
||||
editableText = tester.widget(find.byType(EditableText));
|
||||
expect(editableText.style.color, setColor);
|
||||
|
||||
// inherit: false causes nothing to be merged in from theme
|
||||
await tester.pumpWidget(buildFrame(const TextStyle(
|
||||
fontSize: 24.0,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
inherit: false,
|
||||
)));
|
||||
editableText = tester.widget(find.byType(EditableText));
|
||||
expect(editableText.style.color, isNull);
|
||||
});
|
||||
|
||||
testWidgets('style enforces required fields', (WidgetTester tester) async {
|
||||
Widget buildFrame(TextStyle style) {
|
||||
return MaterialApp(
|
||||
|
|
Loading…
Reference in a new issue