Repository navigation
[material_ui] Handle unknown swipe edges in predictive back transitions - #12502
muhammadkamel wants to merge 5 commits 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.
justinmc
left a comment
There was a problem hiding this comment.
Thanks for porting your PR so quickly!
There's a slight change in process for material_ui and cupertino_ui regarding the changelog and version: you'll have to create a pending changelog yaml file. See https://github.com/flutter/packages/blob/main/packages/material_ui/pending_changelogs/template.yaml
Otherwise this looks good.
| await tester.tap(find.text('push')); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| if (defaultTargetPlatform != TargetPlatform.android) { |
There was a problem hiding this comment.
Should this not be the skip and/or the variant argument of the test itself? For non Android, this test does setup and then no asserts, which reads a bit weird.
There was a problem hiding this comment.
@muhammadkamel Maybe this was missed earlier, but you did not provide a reasoning for adding this return, over using a test variant or test skip?
| await tester.tap(find.text('push')); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| if (defaultTargetPlatform != TargetPlatform.android) { |
|
Thanks for the review @justinmc and @navaronbracke! All comments have been addressed, please take another look. |
|
[from triage] friendly ping @justinmc @navaronbracke are you still reviewing this PR? Thanks! |
navaronbracke
left a comment
There was a problem hiding this comment.
While the overall change SGTM, I did have an open question (from my last review), relating to the use of a return to skip part of the test.
I think it would be better if the tests could be split into an Android version (which uses the full test) and a non-Android version (which uses the part up to the returns in the test body)
| await tester.tap(find.text('push')); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| if (defaultTargetPlatform != TargetPlatform.android) { |
There was a problem hiding this comment.
@muhammadkamel Maybe this was missed earlier, but you did not provide a reasoning for adding this return, over using a test variant or test skip?
Replace the early return on non-Android platforms with TargetPlatformVariant.only(TargetPlatform.android), so the tests only run where they make assertions.
|
Dear @muhammadkamel @navaronbracke |
|
cc @justinmc are you still reviewing this PR or would you like the ecosystem team to take over review? Thanks! |
justinmc
left a comment
There was a problem hiding this comment.
Sorry I was traveling last week but back now. This looks good but I want to make sure adding a value to SwipeEdge is the right approach here, see my comment on that below.
| // `_` keeps the switch exhaustive if additional SwipeEdge values | ||
| // are added in the Flutter SDK. |
There was a problem hiding this comment.
@chunhtai I wonder what you think about this given that your RFC flutter/rfc#32 recommends against adding values to enums (see the framework side of this PR in flutter/flutter#185140). Should we migrate to a class-based SwipeEdge, or should we work with what we have for now?
There was a problem hiding this comment.
this should stay an enum as it is closed by design (at most four directions)
There was a problem hiding this comment.
unless Android start to support micro direction like bottom-left top-left. I doubt that will happen though, better not over-engineering now.
| variant: TargetPlatformVariant.only(TargetPlatform.android), | ||
| ); | ||
|
|
||
| testWidgets('button-triggered back does not start a predictive back animation', ( |
There was a problem hiding this comment.
Nit: Maybe change this to say "system button triggered", since you are talking about Android's system back button, right? To disambiguate it with a Flutter button.
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]///).