diff --git a/packages/flutter/lib/src/widgets/single_child_scroll_view.dart b/packages/flutter/lib/src/widgets/single_child_scroll_view.dart index 9ce4491447..2e67190c71 100644 --- a/packages/flutter/lib/src/widgets/single_child_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/single_child_scroll_view.dart @@ -568,7 +568,10 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix bool _shouldClipAtPaintOffset(Offset paintOffset) { assert(child != null); - return paintOffset < Offset.zero || !(Offset.zero & size).contains((paintOffset & child.size).bottomRight); + return paintOffset.dx < 0 || + paintOffset.dy < 0 || + paintOffset.dx + child.size.width > size.width || + paintOffset.dy + child.size.height > size.height; } @override diff --git a/packages/flutter/test/widgets/single_child_scroll_view_test.dart b/packages/flutter/test/widgets/single_child_scroll_view_test.dart index 8c28192fcb..6b753dfe85 100644 --- a/packages/flutter/test/widgets/single_child_scroll_view_test.dart +++ b/packages/flutter/test/widgets/single_child_scroll_view_test.dart @@ -40,6 +40,69 @@ class TestScrollController extends ScrollController { } void main() { + testWidgets('SingleChildScrollView overflow and clipRect test', (WidgetTester tester) async { + // the test widowSize is Size(800.0, 600.0) + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Container(height: 600.0,) + ) + ) + ); + + // 1st, check that the render object has received the default clip behavior. + final dynamic renderObject = tester.allRenderObjects.where((RenderObject o) => o.runtimeType.toString() == '_RenderSingleChildViewport').first; + expect(renderObject.clipBehavior, equals(Clip.hardEdge)); + + // 2nd, height == widow.height test: check that the painting context does not call pushClipRect . + TestClipPaintingContext context = TestClipPaintingContext(); + renderObject.paint(context, Offset.zero); + expect(context.clipBehavior, equals(Clip.none)); + + // 3rd, height overflow test: check that the painting context call pushClipRect. + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Container(height: 600.1,) + ) + ) + ); + renderObject.paint(context, Offset.zero); + expect(context.clipBehavior, equals(Clip.hardEdge)); + + // 4th, width == widow.width test: check that the painting context do not call pushClipRect. + context = TestClipPaintingContext(); + expect(context.clipBehavior, equals(Clip.none)); // initial value + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Container(width: 800.0,) + ) + ) + ); + renderObject.paint(context, Offset.zero); + expect(context.clipBehavior, equals(Clip.none)); + + // 5th, width overflow test: check that the painting context call pushClipRect. + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Container(width: 800.1,) + ) + ) + ); + renderObject.paint(context, Offset.zero); + expect(context.clipBehavior, equals(Clip.hardEdge)); + }); + testWidgets('SingleChildScrollView respects clipBehavior', (WidgetTester tester) async { await tester.pumpWidget(SingleChildScrollView(child: Container(height: 2000.0)));