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
**Description:**
This PR addresses issue [#140869](flutter/flutter#140869) related to back button handling on root routes in `GoRouterDelegate`. The current `_findCurrentNavigator()` function only assigns `NavigatorState` when it can pop, which prevents `PopScope` and custom back button logic from triggering on root routes, especially on Android. Additionally, the `onExit` callbacks on routes requiring custom exit handling are affected.
**What This PR Changes:**
1. **Modification of `_findCurrentNavigator()`**:
- Removed the conditional `canPop` check, setting `state = navigatorKey.currentState;` directly to ensure `NavigatorState` is always non-null, allowing consistent `PopScope` handling on root routes.
2. **Adjustment of `popRoute()` to Preserve `onExit` Logic**:
- Updated `popRoute()` to call `maybePop()` unconditionally to make sure `PopScope` can handle back button actions on root pages.
- Added fallback to `onExit` logic in `popRoute()` if `maybePop()` does not handle the pop, this way, any route-specific exit callbacks are still functional.
**Impact**:
- **Resolves Inconsistent Back Button Handling**: The fix enables `PopScope` and back button handling on root pages without affecting nested routes or shell routes.
- **Maintains `onExit` Callback Functionality**: `onExit` is invoked when `maybePop()` doesn�t handle the pop, preserving custom exit behaviors.
---
0 commit comments