From 39e00d2ea4991b44027d501e32243c27a6268f47 Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Tue, 9 Jun 2020 11:13:03 -0700 Subject: [PATCH] fix overscroll position if there is sliver before center sliver in custom scroll view (#59015) --- .../lib/src/widgets/overscroll_indicator.dart | 3 ++ .../widgets/overscroll_indicator_test.dart | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/packages/flutter/lib/src/widgets/overscroll_indicator.dart b/packages/flutter/lib/src/widgets/overscroll_indicator.dart index d6e8f16b83..b38916343c 100644 --- a/packages/flutter/lib/src/widgets/overscroll_indicator.dart +++ b/packages/flutter/lib/src/widgets/overscroll_indicator.dart @@ -267,6 +267,9 @@ class _GlowingOverscrollIndicatorState extends State final bool isLeading = controller == _leadingController; if (_lastNotificationType != OverscrollNotification) { final OverscrollIndicatorNotification confirmationNotification = OverscrollIndicatorNotification(leading: isLeading); + // It is possible that the scroll extent starts at non-zero. + if (isLeading) + confirmationNotification.paintOffset = notification.metrics.minScrollExtent; confirmationNotification.dispatch(context); _accepted[isLeading] = confirmationNotification._accepted; if (_accepted[isLeading]) { diff --git a/packages/flutter/test/widgets/overscroll_indicator_test.dart b/packages/flutter/test/widgets/overscroll_indicator_test.dart index 934f98c1da..68d49c325e 100644 --- a/packages/flutter/test/widgets/overscroll_indicator_test.dart +++ b/packages/flutter/test/widgets/overscroll_indicator_test.dart @@ -321,6 +321,45 @@ void main() { expect(painter, isNot(paints..circle()..circle())); }); + testWidgets('CustomScrollView overscroll indicator works if there is sliver before center', (WidgetTester tester) async { + final Key centerKey = UniqueKey(); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: ScrollConfiguration( + behavior: TestScrollBehavior2(), + child: CustomScrollView( + center: centerKey, + physics: const AlwaysScrollableScrollPhysics(), + slivers: [ + SliverList( + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => Text('First sliver $index',), + childCount: 2, + ), + ), + SliverList( + key: centerKey, + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) => Text('Second sliver $index',), + childCount: 5, + ), + ), + ], + ), + ), + ), + ); + + expect(find.text('First sliver 1'), findsNothing); + + await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 300.0)); + expect(find.text('First sliver 1'), findsOneWidget); + final RenderObject painter = tester.renderObject(find.byType(CustomPaint)); + // The scroll offset and paint extend should cancel out each other. + expect(painter, paints..save()..translate(y: 0.0)..scale()..circle()); + }); + group('Modify glow position', () { testWidgets('Leading', (WidgetTester tester) async { await tester.pumpWidget(