Skip to content

Commit 0f5a19a

Browse files
committed
Preserve GridTile dry layout for bounded constraints
1 parent 6ddc5c0 commit 0f5a19a

2 files changed

Lines changed: 75 additions & 25 deletions

File tree

‎packages/material_ui/lib/src/grid_tile.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ class _RenderFillBoundedAxes extends RenderProxyBox {
9696
@override
9797
Size computeDryLayout(BoxConstraints constraints) {
9898
final BoxConstraints childConstraints = _fillBoundedAxes(constraints);
99+
if (childConstraints.isTight) {
100+
return childConstraints.smallest;
101+
}
99102
return constraints.constrain(
100103
child?.getDryLayout(childConstraints) ?? childConstraints.smallest,
101104
);

‎packages/material_ui/test/grid_title_test.dart‎

Lines changed: 72 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,36 @@ void main() {
6060
});
6161

6262
// Regression test for https://github.com/flutter/flutter/issues/82055
63-
testWidgets('GridTile with header and footer sizes itself to its child when unconstrained', (
64-
WidgetTester tester,
65-
) async {
66-
await tester.pumpWidget(
67-
MaterialApp(
68-
home: Center(
69-
child: SizedBox(
70-
height: 100.0,
71-
child: ListView.builder(
72-
scrollDirection: Axis.horizontal,
73-
itemCount: 1,
74-
itemBuilder: (BuildContext context, int index) {
75-
return GridTile(
76-
header: const Text('Header'),
77-
footer: const Text('Footer'),
78-
child: Container(height: 100.0, width: 80.0, color: Colors.red),
79-
);
80-
},
63+
testWidgets(
64+
'GridTile with header and footer sizes itself to its child when the width is unbounded',
65+
(WidgetTester tester) async {
66+
await tester.pumpWidget(
67+
MaterialApp(
68+
home: Center(
69+
child: SizedBox(
70+
height: 100.0,
71+
child: ListView.builder(
72+
scrollDirection: Axis.horizontal,
73+
itemCount: 1,
74+
itemBuilder: (BuildContext context, int index) {
75+
return GridTile(
76+
header: const Text('Header'),
77+
footer: const Text('Footer'),
78+
child: Container(height: 100.0, width: 80.0, color: Colors.red),
79+
);
80+
},
81+
),
8182
),
8283
),
8384
),
84-
),
85-
);
85+
);
8686

87-
expect(tester.takeException(), isNull);
88-
expect(tester.getSize(find.byType(GridTile)), const Size(80.0, 100.0));
89-
expect(find.text('Header'), findsOneWidget);
90-
expect(find.text('Footer'), findsOneWidget);
91-
});
87+
expect(tester.takeException(), isNull);
88+
expect(tester.getSize(find.byType(GridTile)), const Size(80.0, 100.0));
89+
expect(find.text('Header'), findsOneWidget);
90+
expect(find.text('Footer'), findsOneWidget);
91+
},
92+
);
9293

9394
testWidgets('GridTile child fills the tile when the constraints are tight', (
9495
WidgetTester tester,
@@ -176,6 +177,52 @@ void main() {
176177
},
177178
);
178179

180+
testWidgets('GridTile with header and footer reports zero intrinsic sizes', (
181+
WidgetTester tester,
182+
) async {
183+
await tester.pumpWidget(
184+
const MaterialApp(
185+
home: GridTile(
186+
header: Text('Header'),
187+
footer: Text('Footer'),
188+
child: SizedBox(width: 80.0, height: 100.0),
189+
),
190+
),
191+
);
192+
193+
final RenderBox tile = tester.renderObject<RenderBox>(find.byType(GridTile));
194+
expect(tile.getMinIntrinsicWidth(150.0), 0.0);
195+
expect(tile.getMaxIntrinsicWidth(150.0), 0.0);
196+
expect(tile.getMinIntrinsicHeight(200.0), 0.0);
197+
expect(tile.getMaxIntrinsicHeight(200.0), 0.0);
198+
});
199+
200+
testWidgets('GridTile dry layout does not query its child when both axes are bounded', (
201+
WidgetTester tester,
202+
) async {
203+
await tester.pumpWidget(
204+
MaterialApp(
205+
home: GridTile(
206+
header: const Text('Header'),
207+
footer: const Text('Footer'),
208+
child: LayoutBuilder(
209+
builder: (BuildContext context, BoxConstraints constraints) => const SizedBox(),
210+
),
211+
),
212+
),
213+
);
214+
215+
final RenderBox tile = tester.renderObject<RenderBox>(find.byType(GridTile));
216+
expect(
217+
tile.getDryLayout(const BoxConstraints(maxWidth: 200.0, maxHeight: 150.0)),
218+
const Size(200.0, 150.0),
219+
);
220+
expect(
221+
tile.getDryLayout(const BoxConstraints.tightFor(width: 200.0, height: 150.0)),
222+
const Size(200.0, 150.0),
223+
);
224+
});
225+
179226
testWidgets('GridTileBar does not crash at zero area', (WidgetTester tester) async {
180227
await tester.pumpWidget(
181228
const MaterialApp(

0 commit comments

Comments
 (0)