From 09518ac72584f818bdfd85c5830ebe884c6de624 Mon Sep 17 00:00:00 2001 From: Kate Lovett Date: Tue, 21 Feb 2023 21:05:07 +0300 Subject: [PATCH] Remove single axis assertion (#120738) --- .../lib/src/widgets/overscroll_indicator.dart | 6 ++- .../widgets/overscroll_indicator_test.dart | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/overscroll_indicator.dart b/packages/flutter/lib/src/widgets/overscroll_indicator.dart index f6eb74da46..d5a542d72d 100644 --- a/packages/flutter/lib/src/widgets/overscroll_indicator.dart +++ b/packages/flutter/lib/src/widgets/overscroll_indicator.dart @@ -201,6 +201,11 @@ class _GlowingOverscrollIndicatorState extends State if (!widget.notificationPredicate(notification)) { return false; } + if (notification.metrics.axis != widget.axis) { + // This widget is explicitly configured to one axis. If a notification + // from a different axis bubbles up, do nothing. + return false; + } // Update the paint offset with the current scroll position. This makes // sure that the glow effect correctly scrolls in line with the current @@ -236,7 +241,6 @@ class _GlowingOverscrollIndicatorState extends State } } assert(controller != null); - assert(notification.metrics.axis == widget.axis); if (_accepted[isLeading]!) { if (notification.velocity != 0.0) { assert(notification.dragDetails == null); diff --git a/packages/flutter/test/widgets/overscroll_indicator_test.dart b/packages/flutter/test/widgets/overscroll_indicator_test.dart index 7f70630efc..3f4116d107 100644 --- a/packages/flutter/test/widgets/overscroll_indicator_test.dart +++ b/packages/flutter/test/widgets/overscroll_indicator_test.dart @@ -233,6 +233,35 @@ void main() { expect(painter, doesNotOverscroll); }); + testWidgets('Overscroll ignored from alternate axis', (WidgetTester tester) async { + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.ltr, + child: ScrollConfiguration( + behavior: TestScrollBehaviorNoGlow(), + child: GlowingOverscrollIndicator( + axisDirection: AxisDirection.right, + color: Color(0xFF0000FF), + child: CustomScrollView( + physics: AlwaysScrollableScrollPhysics(), + slivers: [ + SliverToBoxAdapter(child: SizedBox(height: 20.0)), + ], + ), + ), + ), + ), + ); + final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); + await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0)); + expect(painter, doesNotOverscroll); + await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, -5.0)); + expect(painter, doesNotOverscroll); + + await tester.pumpAndSettle(const Duration(seconds: 1)); + expect(painter, doesNotOverscroll); + }); + testWidgets('Overscroll horizontally', (WidgetTester tester) async { await tester.pumpWidget( const Directionality( @@ -570,3 +599,12 @@ class TestScrollBehavior2 extends ScrollBehavior { ); } } + +class TestScrollBehaviorNoGlow extends ScrollBehavior { + const TestScrollBehaviorNoGlow(); + + @override + Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) { + return child; + } +}