Skip to content

Commit e74fedc

Browse files
authored
Fix InputDecorator intrinsic height reporting (flutter#55408)
1 parent 8df0d68 commit e74fedc

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

packages/flutter/lib/src/material/input_decorator.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,11 +1243,16 @@ class _RenderDecoration extends RenderBox {
12431243
double subtextHeight = _lineHeight(width, <RenderBox>[helperError, counter]);
12441244
if (subtextHeight > 0.0)
12451245
subtextHeight += subtextGap;
1246-
return contentPadding.top
1246+
final Offset densityOffset = decoration.visualDensity.baseSizeAdjustment;
1247+
final double containerHeight = contentPadding.top
12471248
+ (label == null ? 0.0 : decoration.floatingLabelHeight)
12481249
+ _lineHeight(width, <RenderBox>[prefix, input, suffix])
12491250
+ subtextHeight
12501251
+ contentPadding.bottom;
1252+
final double minContainerHeight = decoration.isDense || expands
1253+
? 0.0
1254+
: kMinInteractiveDimension + densityOffset.dy;
1255+
return math.max(containerHeight, minContainerHeight);
12511256
}
12521257

12531258
@override

packages/flutter/test/material/text_field_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7417,6 +7417,48 @@ void main() {
74177417
final RenderBox renderBox = tester.renderObject(find.byType(TextField));
74187418
expect(renderBox.size.height, lessThan(kMinInteractiveDimension));
74197419
});
7420+
7421+
group('intrinsics', () {
7422+
Widget _buildTest({ bool isDense }) {
7423+
return MaterialApp(
7424+
home: Scaffold(
7425+
body: CustomScrollView(
7426+
slivers: <Widget>[
7427+
SliverFillRemaining(
7428+
hasScrollBody: false,
7429+
child: Column(
7430+
children: <Widget>[
7431+
TextField(
7432+
decoration: InputDecoration(
7433+
isDense: isDense,
7434+
)
7435+
),
7436+
Container(
7437+
height: 1000,
7438+
),
7439+
],
7440+
)
7441+
)
7442+
],
7443+
)
7444+
)
7445+
);
7446+
}
7447+
7448+
testWidgets('By default, intrinsic height is at least kMinInteractiveDimension high', (WidgetTester tester) async {
7449+
// Regression test for https://github.com/flutter/flutter/issues/54729
7450+
// If the intrinsic height does not match that of the height after
7451+
// performLayout, this will fail.
7452+
tester.pumpWidget(_buildTest(isDense: false));
7453+
});
7454+
7455+
testWidgets('When isDense, intrinsic height can go below kMinInteractiveDimension height', (WidgetTester tester) async {
7456+
// Regression test for https://github.com/flutter/flutter/issues/54729
7457+
// If the intrinsic height does not match that of the height after
7458+
// performLayout, this will fail.
7459+
tester.pumpWidget(_buildTest(isDense: true));
7460+
});
7461+
});
74207462
});
74217463
testWidgets("Arrow keys don't move input focus", (WidgetTester tester) async {
74227464
final TextEditingController controller1 = TextEditingController();

0 commit comments

Comments
 (0)