Skip to content

Commit 4acbe97

Browse files
authored
Remove alternate axis assertion from StretchingOverscrollIndicator (#120734)
* remove axes assertion * Update packages/flutter/lib/src/widgets/overscroll_indicator.dart
1 parent 6259b69 commit 4acbe97

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,11 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
707707
if (!widget.notificationPredicate(notification)) {
708708
return false;
709709
}
710+
if (notification.metrics.axis != widget.axis) {
711+
// This widget is explicitly configured to one axis. If a notification
712+
// from a different axis bubbles up, do nothing.
713+
return false;
714+
}
710715

711716
if (notification is OverscrollNotification) {
712717
_lastOverscrollNotification = notification;
@@ -716,7 +721,6 @@ class _StretchingOverscrollIndicatorState extends State<StretchingOverscrollIndi
716721
_accepted = confirmationNotification.accepted;
717722
}
718723

719-
assert(notification.metrics.axis == widget.axis);
720724
if (_accepted) {
721725
_totalOverscroll += notification.overscroll;
722726

packages/flutter/test/widgets/overscroll_stretch_indicator_test.dart

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,65 @@ void main() {
7878
);
7979
}
8080

81+
testWidgets('Stretch overscroll will do nothing when axes do not match', (WidgetTester tester) async {
82+
final GlobalKey box1Key = GlobalKey();
83+
final GlobalKey box2Key = GlobalKey();
84+
final ScrollController controller = ScrollController();
85+
await tester.pumpWidget(
86+
Directionality(
87+
textDirection: TextDirection.ltr,
88+
child: MediaQuery(
89+
data: const MediaQueryData(size: Size(800.0, 600.0)),
90+
child: ScrollConfiguration(
91+
behavior: const ScrollBehavior().copyWith(overscroll: false),
92+
child: StretchingOverscrollIndicator(
93+
axisDirection: AxisDirection.right,
94+
child: CustomScrollView(
95+
controller: controller,
96+
slivers: <Widget>[
97+
SliverToBoxAdapter(child: Container(
98+
color: const Color(0xD0FF0000),
99+
key: box1Key,
100+
height: 250.0,
101+
)),
102+
SliverToBoxAdapter(child: Container(
103+
color: const Color(0xFFFFFF00),
104+
key: box2Key,
105+
height: 250.0,
106+
width: 300.0,
107+
)),
108+
],
109+
),
110+
),
111+
),
112+
),
113+
)
114+
);
115+
116+
expect(find.byType(StretchingOverscrollIndicator), findsOneWidget);
117+
expect(find.byType(GlowingOverscrollIndicator), findsNothing);
118+
final RenderBox box1 = tester.renderObject(find.byKey(box1Key));
119+
final RenderBox box2 = tester.renderObject(find.byKey(box2Key));
120+
121+
expect(controller.offset, 0.0);
122+
expect(box1.localToGlobal(Offset.zero), Offset.zero);
123+
expect(box2.localToGlobal(Offset.zero), const Offset(0.0, 250.0));
124+
125+
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(CustomScrollView)));
126+
// Overscroll the start, no stretching occurs.
127+
await gesture.moveBy(const Offset(0.0, 200.0));
128+
await tester.pumpAndSettle();
129+
expect(box1.localToGlobal(Offset.zero), Offset.zero);
130+
expect(box2.localToGlobal(Offset.zero).dy, 250.0);
131+
132+
await gesture.up();
133+
await tester.pumpAndSettle();
134+
135+
// Overscroll released
136+
expect(box1.localToGlobal(Offset.zero), Offset.zero);
137+
expect(box2.localToGlobal(Offset.zero), const Offset(0.0, 250.0));
138+
});
139+
81140
testWidgets('Stretch overscroll vertically', (WidgetTester tester) async {
82141
final GlobalKey box1Key = GlobalKey();
83142
final GlobalKey box2Key = GlobalKey();

0 commit comments

Comments
 (0)