Repository navigation
fix(1181): Navigator2 - Navigation animation glitches on back gesture (Android only) #1182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
d11b9c8
6288ee4
73ce6ec
baeaa17
a0c46e2
119b123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,3 +32,4 @@ linter: | |
| analyzer: | ||
| exclude: | ||
| - example/ | ||
| - build/** | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,12 +71,26 @@ class RouteNavigatorState extends State<RouteNavigator> { | |
| restorationScopeId: | ||
| widget.navRestorationScopeId ?? widget.router.routeData.name, | ||
| pages: widget.router.stack, | ||
| onDidRemovePage: (page) { | ||
| if (page is StackedPage) { | ||
| var routeData = page.routeData; | ||
| widget.router.removeRoute(routeData); | ||
| widget.didPop?.call(routeData.route, null); | ||
| // ignore: deprecated_member_use | ||
| onPopPage: (route, result) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regression: imperative page removals no longer sync the router stack. With Scenario: app code calls |
||
| // CRITICAL: Using deprecated onPopPage instead of onDidRemovePage | ||
| // because we MUST update router state BEFORE the pop completes. | ||
| // This is essential for Android predictive back gestures to work | ||
| // without animation glitches (double animations or forward replays). | ||
| // onDidRemovePage is called too late (after page removal) and causes | ||
| // page list mismatch during the animation, triggering visual glitches. | ||
| // See: https://github.com/flutter/flutter/issues/new (migration path unclear) | ||
| if (!route.didPop(result)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (route.settings is StackedPage) { | ||
| var page = route.settings as StackedPage; | ||
| widget.router.removeRoute(page.routeData); | ||
| widget.didPop?.call(page.routeData.route, result); | ||
| } | ||
|
|
||
| return true; | ||
| }, | ||
| ) | ||
| : widget.placeholder?.call(context) ?? | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This guard hides the symptom rather than fixing it. When
createRouteruns a second time on the sameStackedPage(for example the page resurrected after an imperative removal, as described onroute_navigator.dart), the page completer has already completed with the first route's result, usuallynullfor a removal. Whatever the live second route pops with is then dropped silently, so a caller awaitingrouter.push<T>()gotnullearly and never sees the real result. Before this change the case showed up as aStateError. Now it loses data without any signal. Consider at least an assert or debug log when the completer is already completed.