|
| 1 | +--- |
| 2 | +title: When a route is removed from the stack, associated futures must complete |
| 3 | +description: > |
| 4 | + Before this breaking change, routes created by Navigator and awaited for |
| 5 | + results could never complete if the route was removed instead of popped. |
| 6 | +--- |
| 7 | + |
| 8 | +## Summary |
| 9 | + |
| 10 | +When routes are pushed, developers can await them to be notified when they are |
| 11 | +popped. However, this didn't work when they were removed because the associated |
| 12 | +future was never completed. |
| 13 | + |
| 14 | +## Context |
| 15 | + |
| 16 | +All Navigator methods that call `remove` had this issue. By using `complete`, |
| 17 | +the issue is properly resolved, allowing developers to pass a result. |
| 18 | + |
| 19 | +## Description of change |
| 20 | + |
| 21 | +All Navigator methods have been updated to no longer call `remove` but instead |
| 22 | +use `complete`. Context menus are now built from the `contextMenuBuilder` |
| 23 | +parameter. |
| 24 | + |
| 25 | +All methods that directly use `complete` now accept an optional `result` |
| 26 | +parameter to return it to the associated future. Other methods that indirectly |
| 27 | +use `remove` currently return `null`. In the future, we might extend these |
| 28 | +methods with an optional callback function to allow developers to handle pop |
| 29 | +logic in indirect scenarios (such as `removeUntil`). |
| 30 | + |
| 31 | +Before this PR, methods bellow can't return a result : |
| 32 | +```dart |
| 33 | +Navigator.of(context).removeRoute(route); |
| 34 | +Navigator.of(context).removeRouteBelow(route); |
| 35 | +``` |
| 36 | + |
| 37 | +After this PR, methods can return a result : |
| 38 | +```dart |
| 39 | +Navigator.of(context).removeRoute(route, result); |
| 40 | +Navigator.of(context).removeRouteBelow(route, result); |
| 41 | +``` |
| 42 | + |
| 43 | +## Migration guide |
| 44 | + |
| 45 | +If you implemented `RouteTransitionRecord` and used `markForRemove`, |
| 46 | +you need to use `markForComplete` instead. `markForRemove` is now deprecated. |
| 47 | + |
| 48 | +For other developers, no changes are required. The navigator continues to work |
| 49 | +as expected with new capabilities. |
| 50 | + |
| 51 | +## Timeline |
| 52 | + |
| 53 | +Landed in version: 3.27.0-1.0.pre.39922 |
| 54 | +In stable release: X.X.X |
| 55 | + |
| 56 | +## References |
| 57 | + |
| 58 | +### API documentation: |
| 59 | + |
| 60 | +* [`RouteTransitionRecord`]({{site.api}}/flutter/widgets/RouteTransitionRecord-class.html) |
| 61 | +* [`Navigator`]({{site.api}}/flutter/widgets/Navigator-class.html) |
| 62 | + |
| 63 | +### Relevant issues: |
| 64 | + |
| 65 | +* [removeRoute unresolved future]({{site.repo.flutter}}/issues/157505) |
| 66 | + |
| 67 | +### Relevant PRs: |
| 68 | + |
| 69 | +* [feat: removeRoute now calls didComplete]({{site.repo.flutter}}/pull/157725) |
0 commit comments