From cf051e7db271a4bf994c6706a3d825eab135a45a Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Thu, 31 Aug 2023 18:50:39 -0500 Subject: [PATCH] Fix clipBehavior ignored in Scrollable of SingleChildScrollView (#133696) Fixes https://github.com/flutter/flutter/issues/133330 The clipBehavior was not passed to the underlying Scrollable, which informs things like the clip on the StretchingOverscrollIndicator. --- .../src/widgets/single_child_scroll_view.dart | 1 + .../single_child_scroll_view_test.dart | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) 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 3255c328eb..d0cec39ae8 100644 --- a/packages/flutter/lib/src/widgets/single_child_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/single_child_scroll_view.dart @@ -248,6 +248,7 @@ class SingleChildScrollView extends StatelessWidget { controller: scrollController, physics: physics, restorationId: restorationId, + clipBehavior: clipBehavior, viewportBuilder: (BuildContext context, ViewportOffset offset) { return _SingleChildViewport( axisDirection: axisDirection, 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 1cf8516611..83b8df226f 100644 --- a/packages/flutter/test/widgets/single_child_scroll_view_test.dart +++ b/packages/flutter/test/widgets/single_child_scroll_view_test.dart @@ -119,13 +119,29 @@ void main() { renderObject.paint(context, Offset.zero); // ignore: avoid_dynamic_calls expect(context.clipBehavior, equals(Clip.hardEdge)); - // 3rd, pump a new widget to check that the render object can update its clip behavior. + // 3rd, check that the underlying Scrollable has the same clipBehavior + // Regression test for https://github.com/flutter/flutter/issues/133330 + Finder scrollable = find.byWidgetPredicate((Widget widget) => widget is Scrollable); + expect( + (tester.widget(scrollable) as Scrollable).clipBehavior, + Clip.hardEdge, + ); + + // 4th, pump a new widget to check that the render object can update its clip behavior. await tester.pumpWidget(SingleChildScrollView(clipBehavior: Clip.antiAlias, child: Container(height: 2000.0))); expect(renderObject.clipBehavior, equals(Clip.antiAlias)); // ignore: avoid_dynamic_calls - // 4th, check that a non-default clip behavior can be sent to the painting context. + // 5th, check that a non-default clip behavior can be sent to the painting context. renderObject.paint(context, Offset.zero); // ignore: avoid_dynamic_calls expect(context.clipBehavior, equals(Clip.antiAlias)); + + // 6th, check that the underlying Scrollable has the same clipBehavior + // Regression test for https://github.com/flutter/flutter/issues/133330 + scrollable = find.byWidgetPredicate((Widget widget) => widget is Scrollable); + expect( + (tester.widget(scrollable) as Scrollable).clipBehavior, + Clip.antiAlias, + ); }); testWidgets('SingleChildScrollView control test', (WidgetTester tester) async {