Don't change the height of the Textfield's labelStyle when it focused. (#141943)

Fixes #141448
This commit is contained in:
yim 2024-01-24 12:13:50 +08:00 committed by GitHub
parent be031cb908
commit 24e7a0be8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View File

@ -2123,9 +2123,9 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
return themeData.textTheme.titleMedium!
.merge(widget.baseStyle)
.copyWith(height: 1)
.merge(defaultTextStyle)
.merge(style);
.merge(style)
.copyWith(height: 1);
}
TextStyle _getHelperStyle(ThemeData themeData, InputDecorationTheme defaults) {

View File

@ -7022,4 +7022,29 @@ testWidgets('OutlineInputBorder with BorderRadius.zero should draw a rectangular
reason: 'clamp is expected',
);
});
testWidgets('Ensure the height of labelStyle remains unchanged when TextField is focused.', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
final ThemeData theme = ThemeData(useMaterial3: true);
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Material(
child: TextField(
focusNode: focusNode,
decoration: const InputDecoration(
labelText: 'label',
),
),
),
),
);
final TextStyle beforeStyle = getLabelStyle(tester);
// Focused.
focusNode.requestFocus();
await tester.pumpAndSettle();
expect(getLabelStyle(tester).height, beforeStyle.height);
});
}