Skip to content

Commit ca1dbb9

Browse files
authored
Fix stretch recede edge case (flutter#90629)
1 parent 115b953 commit ca1dbb9

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

packages/flutter/lib/src/widgets/overscroll_indicator.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,7 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
700700
}
701701
}
702702
}
703-
} else if (notification is ScrollEndNotification && notification.dragDetails != null
704-
|| notification is ScrollUpdateNotification && notification.dragDetails != null) {
703+
} else if (notification is ScrollEndNotification || notification is ScrollUpdateNotification) {
705704
_stretchController.scrollEnd();
706705
}
707706
_lastNotification = notification;

packages/flutter/test/widgets/overscroll_stretch_indicator_test.dart

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void main() {
9797
expect(box3.localToGlobal(Offset.zero).dy, greaterThan(510.0));
9898
await expectLater(
9999
find.byType(CustomScrollView),
100-
matchesGoldenFile('overscroll_stretch.vertical.top.png'),
100+
matchesGoldenFile('overscroll_stretch.vertical.start.stretched.png'),
101101
);
102102

103103
await gesture.up();
@@ -110,7 +110,11 @@ void main() {
110110

111111
// Jump to end of the list
112112
controller.jumpTo(controller.position.maxScrollExtent);
113+
await tester.pumpAndSettle();
113114
expect(controller.offset, 150.0);
115+
expect(box1.localToGlobal(Offset.zero).dy, -150.0);
116+
expect(box2.localToGlobal(Offset.zero).dy, 100.0);
117+
expect(box3.localToGlobal(Offset.zero).dy, 350.0);
114118
await expectLater(
115119
find.byType(CustomScrollView),
116120
matchesGoldenFile('overscroll_stretch.vertical.end.png'),
@@ -125,8 +129,16 @@ void main() {
125129
expect(box3.localToGlobal(Offset.zero).dy, lessThan(350.0));
126130
await expectLater(
127131
find.byType(CustomScrollView),
128-
matchesGoldenFile('overscroll_stretch.vertical.bottom.png'),
132+
matchesGoldenFile('overscroll_stretch.vertical.end.stretched.png'),
129133
);
134+
135+
await gesture.up();
136+
await tester.pumpAndSettle();
137+
138+
// Stretch released back
139+
expect(box1.localToGlobal(Offset.zero).dy, -150.0);
140+
expect(box2.localToGlobal(Offset.zero).dy, 100.0);
141+
expect(box3.localToGlobal(Offset.zero).dy, 350.0);
130142
});
131143

132144
testWidgets('Stretch overscroll works in reverse - vertical', (WidgetTester tester) async {
@@ -162,7 +174,7 @@ void main() {
162174
);
163175
});
164176

165-
testWidgets('Stretch overscroll horizontally', (WidgetTester tester) async {
177+
testWidgets('Stretch overscroll works in reverse - horizontal', (WidgetTester tester) async {
166178
final Key box1Key = UniqueKey();
167179
final Key box2Key = UniqueKey();
168180
final Key box3Key = UniqueKey();
@@ -235,7 +247,7 @@ void main() {
235247
expect(box3.localToGlobal(Offset.zero).dx, greaterThan(610.0));
236248
await expectLater(
237249
find.byType(CustomScrollView),
238-
matchesGoldenFile('overscroll_stretch.horizontal.left.png'),
250+
matchesGoldenFile('overscroll_stretch.horizontal.start.stretched.png'),
239251
);
240252

241253
await gesture.up();
@@ -248,7 +260,11 @@ void main() {
248260

249261
// Jump to end of the list
250262
controller.jumpTo(controller.position.maxScrollExtent);
263+
await tester.pumpAndSettle();
251264
expect(controller.offset, 100.0);
265+
expect(box1.localToGlobal(Offset.zero).dx, -100.0);
266+
expect(box2.localToGlobal(Offset.zero).dx, 200.0);
267+
expect(box3.localToGlobal(Offset.zero).dx, 500.0);
252268
await expectLater(
253269
find.byType(CustomScrollView),
254270
matchesGoldenFile('overscroll_stretch.horizontal.end.png'),
@@ -263,8 +279,16 @@ void main() {
263279
expect(box3.localToGlobal(Offset.zero).dx, lessThan(500.0));
264280
await expectLater(
265281
find.byType(CustomScrollView),
266-
matchesGoldenFile('overscroll_stretch.horizontal.right.png'),
282+
matchesGoldenFile('overscroll_stretch.horizontal.end.stretched.png'),
267283
);
284+
285+
await gesture.up();
286+
await tester.pumpAndSettle();
287+
288+
// Stretch released back
289+
expect(box1.localToGlobal(Offset.zero).dx, -100.0);
290+
expect(box2.localToGlobal(Offset.zero).dx, 200.0);
291+
expect(box3.localToGlobal(Offset.zero).dx, 500.0);
268292
});
269293

270294
testWidgets('Disallow stretching overscroll', (WidgetTester tester) async {

0 commit comments

Comments
 (0)