You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi guys,
I'm having this strange issue since I migrated to navigator2: it seems that the navigation animations are doubled. Or more precisely, the forward animation is replayed before doing the backward animation when using Back gesture on Android (no issue on web, nor iOS).
Here is and example (with timeDilation = 3.0):
puffinpilot-backgesture.mp4
As I'm far from being an expert in this part of Flutter (or even any part), I tried some AI help and it find a solution, but it's using deprecated method.
Does that make any sense to you?
I'll do the PR anyway and try to produce a reproducible example.
Thanks a lot for your expertise!
Happy holidays ✨
AI explanations:
Issue 1: Future Already Completed
Reproduction:
Enable Navigator 2.0 in Stacked (navigator2: true in build.yaml)
Navigate to any route
Perform a back gesture (swipe from edge on iOS/Android)
Error: Bad state: Future already completed
Root Cause:
Navigator 2.0's declarative API rebuilds page stacks during gestures
StackedPage.canUpdate() returns true for matching pages
The same StackedPage instance is reused
createRoute() is called multiple times on the same instance
Each call attempts to complete the same _popCompleter
Error Stack:
Unhandled Exception: Bad state: Future already completed
#0 _AsyncCompleter.complete (dart:async/future_impl.dart:97:31)
Issue 2: Android Animation Glitches
Reproduction:
Run app on Android (especially Android 13+ with predictive back)
Perform back gestures
Observe: forward animation flashes before backward animation
Root Cause:
Navigator widget was using onDidRemovePage callback
Navigator 2.0 requires onPopPage for proper gesture handling
Without onPopPage, Flutter uses default behavior causing mid-gesture rebuilds
Solution
Fix 1: Track Route Listener State (stacked_page.dart)
Added two fields to prevent double-completion:
Route<T>? _currentRoute - Tracks current route instance
bool _hasAttachedListener - Prevents attaching listener multiple times
Describe the bug
Hi guys,
I'm having this strange issue since I migrated to navigator2: it seems that the navigation animations are doubled. Or more precisely, the forward animation is replayed before doing the backward animation when using Back gesture on Android (no issue on web, nor iOS).
Here is and example (with
timeDilation = 3.0):puffinpilot-backgesture.mp4
As I'm far from being an expert in this part of Flutter (or even any part), I tried some AI help and it find a solution, but it's using deprecated method.
Does that make any sense to you?
I'll do the PR anyway and try to produce a reproducible example.
Thanks a lot for your expertise!
Happy holidays ✨
AI explanations:
Issue 1: Future Already Completed
Reproduction:
navigator2: truein build.yaml)Bad state: Future already completedRoot Cause:
StackedPage.canUpdate()returnstruefor matching pagesStackedPageinstance is reusedcreateRoute()is called multiple times on the same instance_popCompleterError Stack:
Issue 2: Android Animation Glitches
Reproduction:
Root Cause:
Navigatorwidget was usingonDidRemovePagecallbackonPopPagefor proper gesture handlingonPopPage, Flutter uses default behavior causing mid-gesture rebuildsSolution
Fix 1: Track Route Listener State (stacked_page.dart)
Added two fields to prevent double-completion:
Route<T>? _currentRoute- Tracks current route instancebool _hasAttachedListener- Prevents attaching listener multiple timesModified
createRoute()to:poppedlistener once per page lifecycleBenefits:
Fix 2: Implement onPopPage (route_navigator.dart)
Replaced
onDidRemovePagewithonPopPagecallback:route.didPop(result)before handlingfalseif pop is cancelled (handles gesture cancellation)truewhen pop succeedsBenefits:
Testing
Tested on:
Test scenarios:
Before fix:
After fix:
Breaking Changes
None. The changes are internal to
StackedPageandRouteNavigatorand maintain backward compatibility.Additional Context
These issues appear when using Navigator 2.0 with the declarative API. Navigator 1.0 is unaffected as it uses imperative navigation.
The fixes follow Flutter's own Navigator 2.0 patterns and align with the official documentation for implementing custom page-based navigation.