Skip to content

Commit

Permalink
Revert "Make RenderSliverGrid more accurately report overflow" (#106123)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield committed Jun 16, 2022
1 parent ede7fc6 commit 995b332
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 54 deletions.
4 changes: 3 additions & 1 deletion packages/flutter/lib/src/rendering/sliver_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
leadingScrollOffset: leadingScrollOffset,
trailingScrollOffset: trailingScrollOffset,
);

final double paintExtent = calculatePaintOffset(
constraints,
from: math.min(constraints.scrollOffset, leadingScrollOffset),
Expand All @@ -674,7 +675,8 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
paintExtent: paintExtent,
maxPaintExtent: estimatedTotalExtent,
cacheExtent: cacheExtent,
hasVisualOverflow: estimatedTotalExtent > paintExtent || constraints.scrollOffset > 0.0 || constraints.overlap != 0.0,
// Conservative to avoid complexity.
hasVisualOverflow: true,
);

// We may have started the layout while scrolled to the end, which
Expand Down
55 changes: 2 additions & 53 deletions packages/flutter/test/widgets/grid_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -645,50 +645,13 @@ void main() {
expect(counters[4], 2);
});

testWidgets('GridView does not report visual overflow unnecessarily', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
children: <Widget>[
Container(height: 200.0),
],
),
),
);

// 1st, check that the render object has received the default clip behavior.
final RenderViewport renderObject = tester.allRenderObjects.whereType<RenderViewport>().first;
expect(renderObject.clipBehavior, equals(Clip.hardEdge));

// The context will get Clip.none because there is no actual visual overflow.
final TestClipPaintingContext context = TestClipPaintingContext();
renderObject.paint(context, Offset.zero);
expect(context.clipBehavior, equals(Clip.none));
});

testWidgets('GridView respects clipBehavior', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
children: <Widget>[
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
],
children: <Widget>[Container(height: 2000.0)],
),
),
);
Expand All @@ -709,21 +672,7 @@ void main() {
child: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
clipBehavior: Clip.antiAlias,
children: <Widget>[
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
],
children: <Widget>[Container(height: 2000.0)],
),
),
);
Expand Down

0 comments on commit 995b332

Please sign in to comment.