Skip to content

fix(1181): Navigator2 - Navigation animation glitches on back gesture (Android only)#1182

Open
n0mad-d3v wants to merge 4 commits intoStacked-Org:masterfrom
n0mad-d3v:fix/navigator-2-future-completion-and-animation
Open

fix(1181): Navigator2 - Navigation animation glitches on back gesture (Android only)#1182
n0mad-d3v wants to merge 4 commits intoStacked-Org:masterfrom
n0mad-d3v:fix/navigator-2-future-completion-and-animation

Conversation

@n0mad-d3v
Copy link

Description

This PR fixes two issues with Navigator 2.0 integration in Stacked's router:

  1. "Future already completed" error during back gestures
  2. Animation glitches on Android (forward flash before backward animation)

Issues

Issue 1: Future Already Completed

Reproduction:

  1. Enable Navigator 2.0 in Stacked (navigator2: true in build.yaml)
  2. Navigate to any route
  3. Perform a back gesture (swipe from edge on iOS/Android)
  4. 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

Deprecated warnings

It uses the deprecated member onPopPage: (route, result) (lib/src/router/widgets/route_navigator.dart) as I didn't find any way to fix that using onDidRemovePage: (page).
Any feedback welcome on that!

Breaking Changes

None. The changes are internal to StackedPage and RouteNavigator and maintain backward compatibility.

Checklist

  • Fixes are limited to the specific issues
  • Code follows existing style/conventions
  • No breaking changes to public API
  • Comments explain the "why" behind changes
  • All existing tests pass
  • Added tests for the fixes (if applicable)
  • Updated documentation (if needed)

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.

Related Issues

#1181

@n0mad-d3v n0mad-d3v changed the title fix(1181): Navigator2 - Navigation animation glitches on back gesture (Android only) fix(#1181): Navigator2 - Navigation animation glitches on back gesture (Android only) Dec 24, 2025
@n0mad-d3v n0mad-d3v changed the title fix(#1181): Navigator2 - Navigation animation glitches on back gesture (Android only) fix(1181): Navigator2 - Navigation animation glitches on back gesture (Android only) Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant