diff --git a/dev/integration_tests/flutter_gallery/lib/demo/material/overscroll_demo.dart b/dev/integration_tests/flutter_gallery/lib/demo/material/overscroll_demo.dart index 235a4cdc31..80b7e3ecec 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/material/overscroll_demo.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/material/overscroll_demo.dart @@ -27,8 +27,10 @@ class OverscrollDemoState extends State { Future _handleRefresh() { final Completer completer = Completer(); - Timer(const Duration(seconds: 3), () { completer.complete(); }); + Timer(const Duration(seconds: 3), () => completer.complete()); return completer.future.then((_) { + if (!mounted) + return; ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: const Text('Refresh complete'), action: SnackBarAction( diff --git a/packages/flutter/lib/src/material/refresh_indicator.dart b/packages/flutter/lib/src/material/refresh_indicator.dart index 6560cd34a2..39ce3646b6 100644 --- a/packages/flutter/lib/src/material/refresh_indicator.dart +++ b/packages/flutter/lib/src/material/refresh_indicator.dart @@ -218,7 +218,8 @@ class RefreshIndicatorState extends State with TickerProviderS bool _handleScrollNotification(ScrollNotification notification) { if (!widget.notificationPredicate(notification)) return false; - if (notification is ScrollStartNotification && notification.metrics.extentBefore == 0.0 && + if ((notification is ScrollStartNotification || notification is ScrollUpdateNotification) && + notification.metrics.extentBefore == 0.0 && _mode == null && _start(notification.metrics.axisDirection)) { setState(() { _mode = _RefreshIndicatorMode.drag; diff --git a/packages/flutter/test/material/refresh_indicator_test.dart b/packages/flutter/test/material/refresh_indicator_test.dart index 073aeaa6d9..aa4e33f09b 100644 --- a/packages/flutter/test/material/refresh_indicator_test.dart +++ b/packages/flutter/test/material/refresh_indicator_test.dart @@ -88,7 +88,6 @@ void main() { await tester.pump(const Duration(seconds: 1)); // finish the indicator hide animation expect(refreshCalled, false); - await tester.fling(find.text('A'), const Offset(0.0, 300.0), 1000.0); // vertical fling await tester.pump(); await tester.pump(const Duration(seconds: 1)); // finish the scroll animation @@ -501,4 +500,73 @@ void main() { 4.0, ); }); + + testWidgets('Top RefreshIndicator showed when dragging from non-zero scroll position', (WidgetTester tester) async { + refreshCalled = false; + final ScrollController scrollController = ScrollController(); + await tester.pumpWidget( + MaterialApp( + home: RefreshIndicator( + onRefresh: holdRefresh, + child: ListView( + controller: scrollController, + physics: const AlwaysScrollableScrollPhysics(), + children: const [ + SizedBox( + height: 200.0, + child: Text('X'), + ), + SizedBox( + height: 800.0, + child: Text('Y'), + ), + ], + ), + ), + ), + ); + + scrollController.jumpTo(50.0); + + await tester.fling(find.text('X'), const Offset(0.0, 300.0), 1000.0); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); // finish the scroll animation + await tester.pump(const Duration(seconds: 1)); // finish the indicator settle animation + expect(tester.getCenter(find.byType(RefreshProgressIndicator)).dy, lessThan(300.0)); + }); + + testWidgets('Bottom RefreshIndicator showed when dragging from non-zero scroll position', (WidgetTester tester) async { + refreshCalled = false; + final ScrollController scrollController = ScrollController(); + await tester.pumpWidget( + MaterialApp( + home: RefreshIndicator( + onRefresh: holdRefresh, + child: ListView( + reverse: true, + controller: scrollController, + physics: const AlwaysScrollableScrollPhysics(), + children: const [ + SizedBox( + height: 200.0, + child: Text('X'), + ), + SizedBox( + height: 800.0, + child: Text('Y'), + ), + ], + ), + ), + ), + ); + + scrollController.jumpTo(50.0); + + await tester.fling(find.text('X'), const Offset(0.0, -300.0), 1000.0); + await tester.pump(); + await tester.pump(const Duration(seconds: 1)); // finish the scroll animation + await tester.pump(const Duration(seconds: 1)); // finish the indicator settle animation + expect(tester.getCenter(find.byType(RefreshProgressIndicator)).dy, greaterThan(300.0)); + }); }