Unverified Commit 6602107b authored by Hans Muller's avatar Hans Muller Committed by GitHub

InputDecorator floating label origin no longer depends on...

InputDecorator floating label origin no longer depends on ThemeData.fixTextFieldOutlineLabel (#92698)
parent 365d76c5
...@@ -516,12 +516,10 @@ class _Decoration { ...@@ -516,12 +516,10 @@ class _Decoration {
this.helperError, this.helperError,
this.counter, this.counter,
this.container, this.container,
this.fixTextFieldOutlineLabel = false,
}) : assert(contentPadding != null), }) : assert(contentPadding != null),
assert(isCollapsed != null), assert(isCollapsed != null),
assert(floatingLabelHeight != null), assert(floatingLabelHeight != null),
assert(floatingLabelProgress != null), assert(floatingLabelProgress != null);
assert(fixTextFieldOutlineLabel != null);
final EdgeInsetsGeometry contentPadding; final EdgeInsetsGeometry contentPadding;
final bool isCollapsed; final bool isCollapsed;
...@@ -543,7 +541,6 @@ class _Decoration { ...@@ -543,7 +541,6 @@ class _Decoration {
final Widget? helperError; final Widget? helperError;
final Widget? counter; final Widget? counter;
final Widget? container; final Widget? container;
final bool fixTextFieldOutlineLabel;
@override @override
bool operator ==(Object other) { bool operator ==(Object other) {
...@@ -571,8 +568,7 @@ class _Decoration { ...@@ -571,8 +568,7 @@ class _Decoration {
&& other.suffixIcon == suffixIcon && other.suffixIcon == suffixIcon
&& other.helperError == helperError && other.helperError == helperError
&& other.counter == counter && other.counter == counter
&& other.container == container && other.container == container;
&& other.fixTextFieldOutlineLabel == fixTextFieldOutlineLabel;
} }
@override @override
...@@ -597,7 +593,6 @@ class _Decoration { ...@@ -597,7 +593,6 @@ class _Decoration {
helperError, helperError,
counter, counter,
container, container,
fixTextFieldOutlineLabel,
); );
} }
} }
...@@ -1518,9 +1513,7 @@ class _RenderDecoration extends RenderBox { ...@@ -1518,9 +1513,7 @@ class _RenderDecoration extends RenderBox {
final bool isOutlineBorder = decoration.border != null && decoration.border!.isOutline; final bool isOutlineBorder = decoration.border != null && decoration.border!.isOutline;
// Temporary opt-in fix for https://github.com/flutter/flutter/issues/54028 // Temporary opt-in fix for https://github.com/flutter/flutter/issues/54028
// Center the scaled label relative to the border. // Center the scaled label relative to the border.
final double floatingY = decoration.fixTextFieldOutlineLabel final double floatingY = isOutlineBorder ? (-labelHeight * _kFinalLabelScale) / 2.0 + borderWeight / 2.0 : contentPadding.top;
? isOutlineBorder ? (-labelHeight * _kFinalLabelScale) / 2.0 + borderWeight / 2.0 : contentPadding.top
: isOutlineBorder ? -labelHeight * 0.25 : contentPadding.top;
final double scale = lerpDouble(1.0, _kFinalLabelScale, t)!; final double scale = lerpDouble(1.0, _kFinalLabelScale, t)!;
final double dx; final double dx;
switch (textDirection) { switch (textDirection) {
...@@ -2161,10 +2154,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2161,10 +2154,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
.merge(widget.baseStyle) .merge(widget.baseStyle)
.merge(defaultStyle) .merge(defaultStyle)
.merge(style) .merge(style)
// Temporary opt-in fix for https://github.com/flutter/flutter/issues/54028 .copyWith(height: 1);
// Setting TextStyle.height to 1 ensures that the label's height will equal
// its font size.
.copyWith(height: themeData.fixTextFieldOutlineLabel ? 1 : null);
} }
// The base style for the inline hint when they're displayed "inline", // The base style for the inline hint when they're displayed "inline",
...@@ -2198,10 +2188,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2198,10 +2188,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
return themeData.textTheme.subtitle1! return themeData.textTheme.subtitle1!
.merge(widget.baseStyle) .merge(widget.baseStyle)
// Temporary opt-in fix for https://github.com/flutter/flutter/issues/54028 .copyWith(height: 1)
// Setting TextStyle.height to 1 ensures that the label's height will equal
// its font size.
.copyWith(height: themeData.fixTextFieldOutlineLabel ? 1 : null)
.merge(getFallbackTextStyle()) .merge(getFallbackTextStyle())
.merge(style); .merge(style);
} }
...@@ -2472,8 +2459,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2472,8 +2459,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
suffixIcon: suffixIcon, suffixIcon: suffixIcon,
helperError: helperError, helperError: helperError,
counter: counter, counter: counter,
container: container, container: container
fixTextFieldOutlineLabel: themeData.fixTextFieldOutlineLabel,
), ),
textDirection: textDirection, textDirection: textDirection,
textBaseline: textBaseline, textBaseline: textBaseline,
......
...@@ -5322,4 +5322,32 @@ void main() { ...@@ -5322,4 +5322,32 @@ 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("InputDecorator's floating label origin no longer depends on ThemeData.fixTextFieldOutlineLabel", (WidgetTester tester) async {
Widget buildFrame(bool fixTextFieldOutlineLabel) {
return buildInputDecorator(
isEmpty: true,
theme: ThemeData.light().copyWith(
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel,
),
decoration: const InputDecoration(
labelText: 'label',
enabledBorder: OutlineInputBorder(),
floatingLabelBehavior: FloatingLabelBehavior.always,
),
);
}
await tester.pumpWidget(buildFrame(false));
await tester.pumpAndSettle();
// floatingLabelHeight = 12 (ahem font size 16dps * 0.75 = 12)
// labelY = -floatingLabelHeight/2 + borderWidth/2
expect(tester.getTopLeft(find.text('label')).dy, -5.5);
await tester.pumpWidget(buildFrame(true));
await tester.pumpAndSettle();
expect(tester.getTopLeft(find.text('label')).dy, -5.5);
});
} }
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