RefreshIndicator can be shown when dragging from non-zero scroll position (#71303)
This commit is contained in:
@@ -27,8 +27,10 @@ class OverscrollDemoState extends State<OverscrollDemo> {
|
||||
|
||||
Future<void> _handleRefresh() {
|
||||
final Completer<void> completer = Completer<void>();
|
||||
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(
|
||||
|
||||
@@ -218,7 +218,8 @@ class RefreshIndicatorState extends State<RefreshIndicator> 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;
|
||||
|
||||
@@ -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 <Widget>[
|
||||
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 <Widget>[
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user