fix initial routes do not run secondary animation when pops#47476
fix initial routes do not run secondary animation when pops#47476fluttergithubbot merged 9 commits intoflutter:masterfrom
Conversation
There was a problem hiding this comment.
@goderbauer you wrote this test. However, something is unclear what the expected behavior should be.
The last pop trigger a train hopping where pri-animation of top most route = 0.16 reverse and sec-animation of the route below =0.67 forward. They will never meet and sec-animation just hang there until everything is disposed. This is what it looks like in real world

There was a problem hiding this comment.
These animations both look broken.
3120b98 to
1746735
Compare
There was a problem hiding this comment.
How do we know that the two trains will never cross in the future?
There was a problem hiding this comment.
The code below also doesn't seem to check that the trains will not cross in the future.
There was a problem hiding this comment.
The check is to detect whether they will cross with the current animations.
There was a problem hiding this comment.
The test below only looks at the current value and the direction of the animation. How's that enough to determine if they will cross? AFIK, the animation values doesn't have to run monotonically from 0.0 to 1.0. It could bounce up and down in between?
There was a problem hiding this comment.
No need to have the else branches here. I would write this as:
if (conditionA)
return ...;
if (conditionB)
return ...;
return ...;There was a problem hiding this comment.
These animations both look broken.
There was a problem hiding this comment.
I wonder if we just need to change this condition to jump directly when the values are the same and to also just jump directly when the nextTrain animation is completed (meaning the next route appeared on top of this route without animation).
There was a problem hiding this comment.
This will only fix the initial route issue. what about the test below?
There was a problem hiding this comment.
Oh, right. So somehow we need to guarantee that we will jump even when the trains haven't crossed at the end of the animation.
4532486 to
95a33c3
Compare
|
@goderbauer This is blocking the work of navigator page api. When you re-arrange the routes and try to update the secondary animation it is really easy to hit this case where the train hopping never finishes because the animation of next route is already completed |
There was a problem hiding this comment.
How do you know at this point that there's an existing train hopping in progress?
There was a problem hiding this comment.
whoever calls this method will need to make sure to set this private field to null as to indicate there is no more train hopping in progress. I think the comment in line 253 is not clear enough, will update
There was a problem hiding this comment.
use _updateSecondaryAnimation to make it clear that you mean this method?
There was a problem hiding this comment.
nit: start with a capital letter ("Secondary").
There was a problem hiding this comment.
Could we just set _trainHoppingListenerRemover to null at the very beginning of this method after we copied it into previousTrainHoppingListenerRemover?
95a33c3 to
c496dee
Compare
|
Hi @chunhtai , do you have a planned date to release this in the stable branch? I'm using nested navigators and the initial route doesn't pop even if I explicitly set initialRoute to false |
|
@ldelafuente This patch does not depend on other file, can you provide a runnable example that reproduce the problem you are having? I don't know when the next stable release will be yet |

Description
Whenever a new route pushed on top of another route, it will chains the secondary animation of bottom route with the primary animation of top route. However, there is a bug in the method that chain them together. In the method, we try to do train hopping if the two animations does not have the same values. It is possible that the two animations are animating with different directions and the hopping will never happen, and that introduce this bug.
here are the steps, assume initial route is routeA/routeB
1, routeA pushed with pri-animation=1.0, sec-animation=0.0
2, routeB pushed with pri-animation=1.0, and it try to do train hopping on sec-animation of routeA which never happen. The sec-animation of routeA stay at 0.0
3, when routeB pop, the routeA didpopnext will try to do the train hopping again with sec-animation of routeA = 0.0 and pri-animation of routeB =1.0 in reverse order. This is wrong because the sec-animation of routeA should be 1.0 at this moment and animate with pri-animation of routeB.
Related Issues
Closes #46000
Tests
I added the following tests:
"secondary animation is triggered when pop initial route"
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.