Skip to content

Commit

Permalink
Remove single axis assertion (#120738)
Browse files Browse the repository at this point in the history
  • Loading branch information
Piinks authored Feb 21, 2023
1 parent 4acbe97 commit 09518ac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/flutter/lib/src/widgets/overscroll_indicator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ class _GlowingOverscrollIndicatorState extends State<GlowingOverscrollIndicator>
if (!widget.notificationPredicate(notification)) {
return false;
}
if (notification.metrics.axis != widget.axis) {
// This widget is explicitly configured to one axis. If a notification
// from a different axis bubbles up, do nothing.
return false;
}

// Update the paint offset with the current scroll position. This makes
// sure that the glow effect correctly scrolls in line with the current
Expand Down Expand Up @@ -236,7 +241,6 @@ class _GlowingOverscrollIndicatorState extends State<GlowingOverscrollIndicator>
}
}
assert(controller != null);
assert(notification.metrics.axis == widget.axis);
if (_accepted[isLeading]!) {
if (notification.velocity != 0.0) {
assert(notification.dragDetails == null);
Expand Down
38 changes: 38 additions & 0 deletions packages/flutter/test/widgets/overscroll_indicator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,35 @@ void main() {
expect(painter, doesNotOverscroll);
});

testWidgets('Overscroll ignored from alternate axis', (WidgetTester tester) async {
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: ScrollConfiguration(
behavior: TestScrollBehaviorNoGlow(),
child: GlowingOverscrollIndicator(
axisDirection: AxisDirection.right,
color: Color(0xFF0000FF),
child: CustomScrollView(
physics: AlwaysScrollableScrollPhysics(),
slivers: <Widget>[
SliverToBoxAdapter(child: SizedBox(height: 20.0)),
],
),
),
),
),
);
final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
expect(painter, doesNotOverscroll);
await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, -5.0));
expect(painter, doesNotOverscroll);

await tester.pumpAndSettle(const Duration(seconds: 1));
expect(painter, doesNotOverscroll);
});

testWidgets('Overscroll horizontally', (WidgetTester tester) async {
await tester.pumpWidget(
const Directionality(
Expand Down Expand Up @@ -570,3 +599,12 @@ class TestScrollBehavior2 extends ScrollBehavior {
);
}
}

class TestScrollBehaviorNoGlow extends ScrollBehavior {
const TestScrollBehaviorNoGlow();

@override
Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) {
return child;
}
}

0 comments on commit 09518ac

Please sign in to comment.