Commit 41c39ba
authored
[go_router] Fix: Consistent PopScope Handling on Root Routes issue #140869 (#8045)
**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.
---1 parent c4fc0e0 commit 41c39ba
File tree
4 files changed
+75
-22
lines changed- packages/go_router
- lib/src
- test
4 files changed
+75
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
1 | 5 | | |
2 | 6 | | |
3 | 7 | | |
| |||
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
| 13 | + | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
61 | 64 | | |
62 | | - | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
68 | 72 | | |
69 | 73 | | |
70 | 74 | | |
| 75 | + | |
71 | 76 | | |
72 | 77 | | |
73 | 78 | | |
| |||
89 | 94 | | |
90 | 95 | | |
91 | 96 | | |
92 | | - | |
| 97 | + | |
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
99 | 104 | | |
100 | | - | |
101 | | - | |
102 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
103 | 108 | | |
104 | 109 | | |
105 | 110 | | |
106 | 111 | | |
107 | | - | |
108 | | - | |
109 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
110 | 117 | | |
111 | 118 | | |
| 119 | + | |
112 | 120 | | |
113 | 121 | | |
114 | 122 | | |
| |||
117 | 125 | | |
118 | 126 | | |
119 | 127 | | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
157 | 165 | | |
158 | 166 | | |
159 | 167 | | |
| |||
162 | 170 | | |
163 | 171 | | |
164 | 172 | | |
| 173 | + | |
| 174 | + | |
165 | 175 | | |
| 176 | + | |
166 | 177 | | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
171 | 181 | | |
172 | 182 | | |
173 | 183 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
95 | 133 | | |
96 | 134 | | |
97 | 135 | | |
| |||
0 commit comments