Unverified Commit a0e333bd authored by Dan Field's avatar Dan Field Committed by GitHub

Make RenderSliverGrid more accurately report overflow (#104064)

* Make RenderSliverGrid more accurately report overflow

* Update packages/flutter/lib/src/rendering/sliver_grid.dart
Co-authored-by: 's avatarKate Lovett <katelovett@google.com>
Co-authored-by: 's avatarKate Lovett <katelovett@google.com>
parent 589dd802
...@@ -658,7 +658,6 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor { ...@@ -658,7 +658,6 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
leadingScrollOffset: leadingScrollOffset, leadingScrollOffset: leadingScrollOffset,
trailingScrollOffset: trailingScrollOffset, trailingScrollOffset: trailingScrollOffset,
); );
final double paintExtent = calculatePaintOffset( final double paintExtent = calculatePaintOffset(
constraints, constraints,
from: math.min(constraints.scrollOffset, leadingScrollOffset), from: math.min(constraints.scrollOffset, leadingScrollOffset),
...@@ -675,8 +674,7 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor { ...@@ -675,8 +674,7 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
paintExtent: paintExtent, paintExtent: paintExtent,
maxPaintExtent: estimatedTotalExtent, maxPaintExtent: estimatedTotalExtent,
cacheExtent: cacheExtent, cacheExtent: cacheExtent,
// Conservative to avoid complexity. hasVisualOverflow: estimatedTotalExtent > paintExtent || constraints.scrollOffset > 0.0 || constraints.overlap != 0.0,
hasVisualOverflow: true,
); );
// We may have started the layout while scrolled to the end, which // We may have started the layout while scrolled to the end, which
......
...@@ -645,13 +645,50 @@ void main() { ...@@ -645,13 +645,50 @@ void main() {
expect(counters[4], 2); 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 { testWidgets('GridView respects clipBehavior', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: GridView( child: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
children: <Widget>[Container(height: 2000.0)], 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),
],
), ),
), ),
); );
...@@ -672,7 +709,21 @@ void main() { ...@@ -672,7 +709,21 @@ void main() {
child: GridView( child: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3), gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
children: <Widget>[Container(height: 2000.0)], 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),
],
), ),
), ),
); );
......
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