Unverified Commit 8fbfe1cf authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Text field height fix (#55911)

parent 9bfe50cb
...@@ -1075,7 +1075,7 @@ class _RenderDecoration extends RenderBox { ...@@ -1075,7 +1075,7 @@ class _RenderDecoration extends RenderBox {
+ contentPadding.bottom + contentPadding.bottom
+ densityOffset.dy, + densityOffset.dy,
); );
final double minContainerHeight = decoration.isDense || expands final double minContainerHeight = decoration.isDense || decoration.isCollapsed || expands
? 0.0 ? 0.0
: kMinInteractiveDimension + densityOffset.dy; : kMinInteractiveDimension + densityOffset.dy;
final double maxContainerHeight = boxConstraints.maxHeight - bottomHeight + densityOffset.dy; final double maxContainerHeight = boxConstraints.maxHeight - bottomHeight + densityOffset.dy;
...@@ -2511,6 +2511,7 @@ class InputDecoration { ...@@ -2511,6 +2511,7 @@ class InputDecoration {
) )
this.hasFloatingPlaceholder = true, // ignore: deprecated_member_use_from_same_package this.hasFloatingPlaceholder = true, // ignore: deprecated_member_use_from_same_package
this.floatingLabelBehavior = FloatingLabelBehavior.auto, this.floatingLabelBehavior = FloatingLabelBehavior.auto,
this.isCollapsed = false,
this.isDense, this.isDense,
this.contentPadding, this.contentPadding,
this.prefixIcon, this.prefixIcon,
...@@ -2541,8 +2542,7 @@ class InputDecoration { ...@@ -2541,8 +2542,7 @@ class InputDecoration {
this.alignLabelWithHint, this.alignLabelWithHint,
}) : assert(enabled != null), }) : assert(enabled != null),
assert(!(prefix != null && prefixText != null), 'Declaring both prefix and prefixText is not supported.'), assert(!(prefix != null && prefixText != null), 'Declaring both prefix and prefixText is not supported.'),
assert(!(suffix != null && suffixText != null), 'Declaring both suffix and suffixText is not supported.'), assert(!(suffix != null && suffixText != null), 'Declaring both suffix and suffixText is not supported.');
isCollapsed = false;
/// Defines an [InputDecorator] that is the same size as the input field. /// Defines an [InputDecorator] that is the same size as the input field.
/// ///
...@@ -3303,8 +3303,6 @@ class InputDecoration { ...@@ -3303,8 +3303,6 @@ class InputDecoration {
/// Creates a copy of this input decoration with the given fields replaced /// Creates a copy of this input decoration with the given fields replaced
/// by the new values. /// by the new values.
///
/// Always sets [isCollapsed] to false.
InputDecoration copyWith({ InputDecoration copyWith({
Widget icon, Widget icon,
String labelText, String labelText,
...@@ -3320,6 +3318,7 @@ class InputDecoration { ...@@ -3320,6 +3318,7 @@ class InputDecoration {
int errorMaxLines, int errorMaxLines,
bool hasFloatingPlaceholder, bool hasFloatingPlaceholder,
FloatingLabelBehavior floatingLabelBehavior, FloatingLabelBehavior floatingLabelBehavior,
bool isCollapsed,
bool isDense, bool isDense,
EdgeInsetsGeometry contentPadding, EdgeInsetsGeometry contentPadding,
Widget prefixIcon, Widget prefixIcon,
...@@ -3365,6 +3364,7 @@ class InputDecoration { ...@@ -3365,6 +3364,7 @@ class InputDecoration {
// ignore: deprecated_member_use_from_same_package // ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder: hasFloatingPlaceholder ?? this.hasFloatingPlaceholder, hasFloatingPlaceholder: hasFloatingPlaceholder ?? this.hasFloatingPlaceholder,
floatingLabelBehavior: floatingLabelBehavior ?? this.floatingLabelBehavior, floatingLabelBehavior: floatingLabelBehavior ?? this.floatingLabelBehavior,
isCollapsed: isCollapsed ?? this.isCollapsed,
isDense: isDense ?? this.isDense, isDense: isDense ?? this.isDense,
contentPadding: contentPadding ?? this.contentPadding, contentPadding: contentPadding ?? this.contentPadding,
prefixIcon: prefixIcon ?? this.prefixIcon, prefixIcon: prefixIcon ?? this.prefixIcon,
...@@ -3412,6 +3412,7 @@ class InputDecoration { ...@@ -3412,6 +3412,7 @@ class InputDecoration {
// ignore: deprecated_member_use_from_same_package // ignore: deprecated_member_use_from_same_package
hasFloatingPlaceholder: hasFloatingPlaceholder ?? theme.hasFloatingPlaceholder, hasFloatingPlaceholder: hasFloatingPlaceholder ?? theme.hasFloatingPlaceholder,
floatingLabelBehavior: floatingLabelBehavior ?? theme.floatingLabelBehavior, floatingLabelBehavior: floatingLabelBehavior ?? theme.floatingLabelBehavior,
isCollapsed: isCollapsed ?? theme.isCollapsed,
isDense: isDense ?? theme.isDense, isDense: isDense ?? theme.isDense,
contentPadding: contentPadding ?? theme.contentPadding, contentPadding: contentPadding ?? theme.contentPadding,
prefixStyle: prefixStyle ?? theme.prefixStyle, prefixStyle: prefixStyle ?? theme.prefixStyle,
......
...@@ -2243,7 +2243,6 @@ void main() { ...@@ -2243,7 +2243,6 @@ void main() {
), ),
), ),
); );
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, kMinInteractiveDimension)); expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, kMinInteractiveDimension));
expect(tester.getTopLeft(find.text('text')).dy, 15.0); expect(tester.getTopLeft(find.text('text')).dy, 15.0);
expect(tester.getBottomLeft(find.text('text')).dy, 31.0); expect(tester.getBottomLeft(find.text('text')).dy, 31.0);
...@@ -2630,25 +2629,99 @@ void main() { ...@@ -2630,25 +2629,99 @@ void main() {
expect(getBorderWeight(tester), 1.0); expect(getBorderWeight(tester), 1.0);
}); });
testWidgets('InputDecorator.collapsed', (WidgetTester tester) async { testWidgets('contentPadding smaller than kMinInteractiveDimension', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/42449
const double verticalPadding = 1.0;
await tester.pumpWidget(
buildInputDecorator(
// isEmpty: false (default),
// isFocused: false (default)
decoration: const InputDecoration(
hintText: 'hint',
contentPadding: EdgeInsets.symmetric(vertical: verticalPadding),
isDense: true,
),
),
);
// The overall height is 18dps. This is shorter than
// kMinInteractiveDimension, but because isDense is true, the minimum is
// ignored.
// 16 - input text (ahem font size 16dps)
// 2 - total vertical padding
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 18.0));
expect(tester.getSize(find.text('text')).height, 16.0);
expect(tester.getTopLeft(find.text('text')).dy, 1.0);
expect(getOpacity(tester, 'hint'), 0.0);
expect(getBorderWeight(tester), 1.0);
await tester.pumpWidget( await tester.pumpWidget(
buildInputDecorator( buildInputDecorator(
// isEmpty: false (default), // isEmpty: false (default),
// isFocused: false (default) // isFocused: false (default)
decoration: const InputDecoration.collapsed( decoration: const InputDecoration.collapsed(
hintText: 'hint', hintText: 'hint',
// InputDecoration.collapsed does not support contentPadding
), ),
), ),
); );
// Overall height for this InputDecorator is 16dps: // The overall height is 16dps. This is shorter than
// kMinInteractiveDimension, but because isCollapsed is true, the minimum is
// ignored. There is no padding at all, because isCollapsed doesn't support
// contentPadding.
// 16 - input text (ahem font size 16dps) // 16 - input text (ahem font size 16dps)
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, kMinInteractiveDimension)); // 16 bumped up to minimum. expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 16.0));
expect(tester.getSize(find.text('text')).height, 16.0);
expect(tester.getTopLeft(find.text('text')).dy, 0.0);
expect(getOpacity(tester, 'hint'), 0.0);
expect(getBorderWeight(tester), 1.0);
await tester.pumpWidget(
buildInputDecorator(
// isEmpty: false (default),
// isFocused: false (default)
decoration: const InputDecoration(
hintText: 'hint',
contentPadding: EdgeInsets.symmetric(vertical: verticalPadding),
),
),
);
// The requested overall height is 18dps, however the minimum height is
// kMinInteractiveDimension because neither isDense or isCollapsed are true.
// 16 - input text (ahem font size 16dps)
// 2 - total vertical padding
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, kMinInteractiveDimension));
expect(tester.getSize(find.text('text')).height, 16.0); expect(tester.getSize(find.text('text')).height, 16.0);
expect(tester.getTopLeft(find.text('text')).dy, 16.0); expect(tester.getTopLeft(find.text('text')).dy, 16.0);
expect(getOpacity(tester, 'hint'), 0.0); expect(getOpacity(tester, 'hint'), 0.0);
expect(getBorderWeight(tester), 0.0); expect(getBorderWeight(tester), 0.0);
});
testWidgets('InputDecorator.collapsed', (WidgetTester tester) async {
await tester.pumpWidget(
buildInputDecorator(
// isEmpty: false (default),
// isFocused: false (default)
decoration: const InputDecoration.collapsed(
hintText: 'hint',
),
),
);
// Overall height for this InputDecorator is 16dps. There is no minimum
// height when InputDecoration.collapsed is used.
// 16 - input text (ahem font size 16dps)
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 16.0));
expect(tester.getSize(find.text('text')).height, 16.0);
expect(tester.getTopLeft(find.text('text')).dy, 0.0);
expect(getOpacity(tester, 'hint'), 0.0);
expect(getBorderWeight(tester), 0.0);
// The hint should appear // The hint should appear
await tester.pumpWidget( await tester.pumpWidget(
...@@ -2662,11 +2735,11 @@ void main() { ...@@ -2662,11 +2735,11 @@ void main() {
); );
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, kMinInteractiveDimension)); expect(tester.getSize(find.byType(InputDecorator)), const Size(800.0, 16.0));
expect(tester.getSize(find.text('text')).height, 16.0); expect(tester.getSize(find.text('text')).height, 16.0);
expect(tester.getTopLeft(find.text('text')).dy, 16.0); expect(tester.getTopLeft(find.text('text')).dy, 0.0);
expect(tester.getSize(find.text('hint')).height, 16.0); expect(tester.getSize(find.text('hint')).height, 16.0);
expect(tester.getTopLeft(find.text('hint')).dy, 16.0); expect(tester.getTopLeft(find.text('hint')).dy, 0.0);
expect(getBorderWeight(tester), 0.0); expect(getBorderWeight(tester), 0.0);
}); });
......
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