Skip to content

Commit 09518ac

Browse files
authored
Remove single axis assertion (#120738)
1 parent 4acbe97 commit 09518ac

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ class _GlowingOverscrollIndicatorState extends State<GlowingOverscrollIndicator>
201201
if (!widget.notificationPredicate(notification)) {
202202
return false;
203203
}
204+
if (notification.metrics.axis != widget.axis) {
205+
// This widget is explicitly configured to one axis. If a notification
206+
// from a different axis bubbles up, do nothing.
207+
return false;
208+
}
204209

205210
// Update the paint offset with the current scroll position. This makes
206211
// sure that the glow effect correctly scrolls in line with the current
@@ -236,7 +241,6 @@ class _GlowingOverscrollIndicatorState extends State<GlowingOverscrollIndicator>
236241
}
237242
}
238243
assert(controller != null);
239-
assert(notification.metrics.axis == widget.axis);
240244
if (_accepted[isLeading]!) {
241245
if (notification.velocity != 0.0) {
242246
assert(notification.dragDetails == null);

packages/flutter/test/widgets/overscroll_indicator_test.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,35 @@ void main() {
233233
expect(painter, doesNotOverscroll);
234234
});
235235

236+
testWidgets('Overscroll ignored from alternate axis', (WidgetTester tester) async {
237+
await tester.pumpWidget(
238+
const Directionality(
239+
textDirection: TextDirection.ltr,
240+
child: ScrollConfiguration(
241+
behavior: TestScrollBehaviorNoGlow(),
242+
child: GlowingOverscrollIndicator(
243+
axisDirection: AxisDirection.right,
244+
color: Color(0xFF0000FF),
245+
child: CustomScrollView(
246+
physics: AlwaysScrollableScrollPhysics(),
247+
slivers: <Widget>[
248+
SliverToBoxAdapter(child: SizedBox(height: 20.0)),
249+
],
250+
),
251+
),
252+
),
253+
),
254+
);
255+
final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
256+
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
257+
expect(painter, doesNotOverscroll);
258+
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, -5.0));
259+
expect(painter, doesNotOverscroll);
260+
261+
await tester.pumpAndSettle(const Duration(seconds: 1));
262+
expect(painter, doesNotOverscroll);
263+
});
264+
236265
testWidgets('Overscroll horizontally', (WidgetTester tester) async {
237266
await tester.pumpWidget(
238267
const Directionality(
@@ -570,3 +599,12 @@ class TestScrollBehavior2 extends ScrollBehavior {
570599
);
571600
}
572601
}
602+
603+
class TestScrollBehaviorNoGlow extends ScrollBehavior {
604+
const TestScrollBehaviorNoGlow();
605+
606+
@override
607+
Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) {
608+
return child;
609+
}
610+
}

0 commit comments

Comments
 (0)