Unverified Commit a3dd5aea authored by xubaolin's avatar xubaolin Committed by GitHub

ScrollController.jumpTo zero should not trigger the refresh indicator (#75764)

parent fe0ceeb8
......@@ -262,7 +262,11 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
}
bool _shouldStart(ScrollNotification notification) {
return (notification is ScrollStartNotification || (notification is ScrollUpdateNotification && notification.dragDetails != null && widget.triggerMode == RefreshIndicatorTriggerMode.anywhere))
// If the notification.dragDetails is null, this scroll is not triggered by
// user dragging. It may be a result of ScrollController.jumpTo or ballistic scroll.
// In this case, we don't want to trigger the refresh indicator.
return ((notification is ScrollStartNotification && notification.dragDetails != null)
|| (notification is ScrollUpdateNotification && notification.dragDetails != null && widget.triggerMode == RefreshIndicatorTriggerMode.anywhere))
&& notification.metrics.extentBefore == 0.0
&& _mode == null
&& _start(notification.metrics.axisDirection);
......
......@@ -677,6 +677,38 @@ void main() {
expect(find.byType(RefreshProgressIndicator), findsNothing);
});
testWidgets('ScrollController.jumpTo should not trigger the refresh indicator', (WidgetTester tester) async {
refreshCalled = false;
final ScrollController scrollController = ScrollController(initialScrollOffset: 500.0);
await tester.pumpWidget(
MaterialApp(
home: RefreshIndicator(
onRefresh: refresh,
child: ListView(
controller: scrollController,
physics: const AlwaysScrollableScrollPhysics(),
children: const <Widget>[
SizedBox(
height: 800.0,
child: Text('X'),
),
SizedBox(
height: 800.0,
child: Text('Y'),
),
],
),
),
),
);
scrollController.jumpTo(0.0);
await tester.pump(const Duration(seconds: 1)); // finish the indicator settle animation
await tester.pump(const Duration(seconds: 1)); // finish the indicator hide animation
expect(refreshCalled, false);
});
testWidgets('RefreshIndicator.color can be updated at runtime', (WidgetTester tester) async {
refreshCalled = false;
Color refreshIndicatorColor = Colors.green;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment