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

This commit is contained in:
xubaolin 2021-02-18 03:11:02 +08:00 committed by GitHub
parent fe0ceeb80d
commit a3dd5aeaad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View File

@ -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);

View File

@ -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;