Unverified Commit de0aab17 authored by Varun Kamani's avatar Varun Kamani Committed by GitHub

Issue 88543: TextField labelText doesn't get hintTextStyle when labelTextStyle...

Issue 88543: TextField labelText doesn't get hintTextStyle when labelTextStyle is non-null Fixed (#89386)

labelText now gets hintTextStyle when no labelStyle, per the docs
parent f9ff8343
...@@ -2231,12 +2231,14 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2231,12 +2231,14 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
isHovering: isHovering, isHovering: isHovering,
); );
final TextStyle? inlineLabelStyle = decoration!.label != null ? decoration!.labelStyle : decoration!.hintStyle;
// Temporary opt-in fix for https://github.com/flutter/flutter/issues/54028 // Temporary opt-in fix for https://github.com/flutter/flutter/issues/54028
// Setting TextStyle.height to 1 ensures that the label's height will equal // Setting TextStyle.height to 1 ensures that the label's height will equal
// its font size. // its font size.
final TextStyle inlineLabelStyle = themeData.fixTextFieldOutlineLabel final TextStyle effectiveInlineLabelStyle = themeData.fixTextFieldOutlineLabel
? inlineStyle.merge(decoration!.labelStyle).copyWith(height: 1) ? inlineStyle.merge(inlineLabelStyle).copyWith(height: 1)
: inlineStyle.merge(decoration!.labelStyle); : inlineStyle.merge(inlineLabelStyle);
final Widget? label = decoration!.labelText == null && decoration!.label == null ? null : _Shaker( final Widget? label = decoration!.labelText == null && decoration!.label == null ? null : _Shaker(
animation: _shakingLabelController.view, animation: _shakingLabelController.view,
child: AnimatedOpacity( child: AnimatedOpacity(
...@@ -2248,7 +2250,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2248,7 +2250,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
curve: _kTransitionCurve, curve: _kTransitionCurve,
style: widget._labelShouldWithdraw style: widget._labelShouldWithdraw
? _getFloatingLabelStyle(themeData) ? _getFloatingLabelStyle(themeData)
: inlineLabelStyle, : effectiveInlineLabelStyle,
child: decoration!.label ?? Text( child: decoration!.label ?? Text(
decoration!.labelText!, decoration!.labelText!,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
...@@ -2371,7 +2373,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2371,7 +2373,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
contentPadding = decorationContentPadding ?? EdgeInsets.zero; contentPadding = decorationContentPadding ?? EdgeInsets.zero;
} else if (!border.isOutline) { } else if (!border.isOutline) {
// 4.0: the vertical gap between the inline elements and the floating label. // 4.0: the vertical gap between the inline elements and the floating label.
floatingLabelHeight = (4.0 + 0.75 * inlineLabelStyle.fontSize!) * MediaQuery.textScaleFactorOf(context); floatingLabelHeight = (4.0 + 0.75 * effectiveInlineLabelStyle.fontSize!) * MediaQuery.textScaleFactorOf(context);
if (decoration!.filled == true) { // filled == null same as filled == false if (decoration!.filled == true) { // filled == null same as filled == false
contentPadding = decorationContentPadding ?? (decorationIsDense contentPadding = decorationContentPadding ?? (decorationIsDense
? const EdgeInsets.fromLTRB(12.0, 8.0, 12.0, 8.0) ? const EdgeInsets.fromLTRB(12.0, 8.0, 12.0, 8.0)
......
...@@ -3422,7 +3422,7 @@ void main() { ...@@ -3422,7 +3422,7 @@ void main() {
expect(tester.widget<Text>(find.text('suffix')).style!.color, suffixStyle.color); expect(tester.widget<Text>(find.text('suffix')).style!.color, suffixStyle.color);
expect(tester.widget<Text>(find.text('helper')).style!.color, helperStyle.color); expect(tester.widget<Text>(find.text('helper')).style!.color, helperStyle.color);
expect(tester.widget<Text>(find.text('counter')).style!.color, counterStyle.color); expect(tester.widget<Text>(find.text('counter')).style!.color, counterStyle.color);
expect(getLabelStyle(tester).color, labelStyle.color); expect(getLabelStyle(tester).color, hintStyle.color);
}); });
testWidgets('InputDecorationTheme style overrides (focused)', (WidgetTester tester) async { testWidgets('InputDecorationTheme style overrides (focused)', (WidgetTester tester) async {
...@@ -5244,4 +5244,66 @@ void main() { ...@@ -5244,4 +5244,66 @@ void main() {
// Verify that the styles were passed along // Verify that the styles were passed along
expect(getLabelStyle(tester).color, labelStyle.color); expect(getLabelStyle(tester).color, labelStyle.color);
}); });
testWidgets('hintStyle is used for labelText when labelText is on top of the input field and labelStyle is used for labelText when labelText moves above widget', (WidgetTester tester) async {
const TextStyle style16 = TextStyle(fontFamily: 'Ahem', fontSize: 16.0);
final TextStyle labelStyle = style16.merge(const TextStyle(color: Colors.purple));
final TextStyle hintStyle = style16.merge(const TextStyle(color: Colors.red));
await tester.pumpWidget(
buildInputDecorator(
isEmpty: true,
isFocused: false, // Label appears inline, on top of the input field.
decoration: InputDecoration(
labelText: 'label',
labelStyle: labelStyle,
hintStyle: hintStyle,
),
),
);
// Overall height for this InputDecorator is 56dps:
// 12 - top padding
// 12 - floating label (ahem font size 16dps * 0.75 = 12)
// 4 - floating label / input text gap
// 16 - input text (ahem font size 16dps)
// 12 - bottom padding
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 56.0));
expect(tester.getTopLeft(find.text('label')).dy, 20.0);
expect(tester.getBottomLeft(find.text('label')).dy, 36.0);
expect(getBorderBottom(tester), 56.0);
expect(getBorderWeight(tester), 1.0);
// Verify that the hintStyle was used
expect(getLabelStyle(tester).color, hintStyle.color);
await tester.pumpWidget(
buildInputDecorator(
isEmpty: true,
isFocused: true, // Label moves above (i.e., vertically adjacent to) the input field
decoration: InputDecoration(
labelText: 'label',
labelStyle: labelStyle,
hintStyle: hintStyle,
),
),
);
await tester.pumpAndSettle();
// Overall height for this InputDecorator is 56dps:
// 12 - top padding
// 12 - floating label (ahem font size 16dps * 0.75 = 12)
// 4 - floating label / input text gap
// 16 - input text (ahem font size 16dps)
// 12 - bottom padding
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 56.0));
expect(tester.getTopLeft(find.text('label')).dy, 12.0);
expect(tester.getBottomLeft(find.text('label')).dy, 24.0);
expect(getBorderBottom(tester), 56.0);
expect(getBorderWeight(tester), 2.0);
// Verify that the labelStyle was used
expect(getLabelStyle(tester).color, labelStyle.color);
});
} }
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