mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
ScrollController.jumpTo zero should not trigger the refresh indicator (#75764)
This commit is contained in:
parent
fe0ceeb80d
commit
a3dd5aeaad
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user