[material_ui] Handle unknown swipe edges in predictive back transitions - #12502
[material_ui] Handle unknown swipe edges in predictive back transitions#12502muhammadkamel wants to merge 1 commit into
Conversation
Treat unknown or button-triggered swipe edges as a no-direction fallback so the switch stays exhaustive when the Flutter SDK adds SwipeEdge values.
There was a problem hiding this comment.
Code Review
This pull request updates PredictiveBackPageTransitionsBuilder to treat unknown or button-triggered swipe edges as a no-direction fallback, and adds tests for right-edge swipes and button-triggered back events. The review feedback suggests simplifying the switch expression by removing the redundant SwipeEdge.left case, and using a more precise assertion in the tests to verify that the page shifts in the correct direction.
| SwipeEdge.left => Offset(xShift, _getYShiftPosition(screenSize.height)), | ||
| SwipeEdge.right => Offset(-xShift, _getYShiftPosition(screenSize.height)), | ||
| null => Offset(xShift, _getYShiftPosition(screenSize.height)), | ||
| // Button-triggered back (Android BackEvent.EDGE_NONE) has no swipe | ||
| // direction. Button events are filtered out in handleStartBackGesture, | ||
| // so this is a safe fallback matching the null (no event) case. | ||
| // `_` keeps the switch exhaustive if additional SwipeEdge values | ||
| // are added in the Flutter SDK. | ||
| _ => Offset(xShift, _getYShiftPosition(screenSize.height)), |
There was a problem hiding this comment.
Since SwipeEdge.left and the wildcard _ fallback both return the exact same offset Offset(xShift, _getYShiftPosition(screenSize.height)), we can simplify the switch expression by removing the redundant SwipeEdge.left case and letting the wildcard pattern handle it.
SwipeEdge.right => Offset(-xShift, _getYShiftPosition(screenSize.height)),
// Button-triggered back (Android BackEvent.EDGE_NONE) has no swipe
// direction. Button events are filtered out in handleStartBackGesture,
// so this is a safe fallback matching the null (no event) case.
// The wildcard pattern keeps the switch exhaustive if additional SwipeEdge
// values are added in the Flutter SDK, and also handles SwipeEdge.left.
_ => Offset(xShift, _getYShiftPosition(screenSize.height)),| // is driven by the transition animation and will be non-zero (the exact | ||
| // direction depends on which layer the tween is applied to). | ||
| final Offset pageBOffset = tester.getTopLeft(find.text('page b')); | ||
| expect(pageBOffset.dx, isNot(0.0)); |
There was a problem hiding this comment.
For a right-edge swipe, the page is expected to shift to the left (negative dx). Using lessThan(0.0) instead of isNot(0.0) provides a more precise and robust assertion, ensuring the page shifts in the correct direction.
| expect(pageBOffset.dx, isNot(0.0)); | |
| expect(pageBOffset.dx, lessThan(0.0)); |
Ports the Material side of flutter/flutter#185140 after the Material/Cupertino decoupling.
PredictiveBackPageTransitionsBuildernow treats unknown or button-triggered swipe edges as a no-direction fallback, matching AndroidBackEvent.EDGE_NONE._is used instead ofSwipeEdge.nonebecause that enum value is not in the Flutter SDK this package currently compiles against; it also keeps the switch exhaustive when the SDK gains newSwipeEdgevalues.Adds coverage for right-edge swipes and for button-triggered back events (
Offset.zero+progress: 0.0), whichhandleStartBackGesturealready filters viaisButtonEvent.The
RangeErrorinPredictiveBackEvent.fromMapforswipeEdge: 2still lives influtter/servicesand is fixed in flutter/flutter#191306. That crash cannot be fixed in this package.Fixes flutter/flutter#186168
Pre-Review Checklist
[shared_preferences]///).