When a route is removed from the stack, associated futures must complete
Summary
#When routes are pushed, developers can await them to be notified when they are popped. However, this didn't work when they were removed because the associated future was never completed.
Context
#All Navigator methods that call remove
had this issue. By using complete
,
the issue is properly resolved, allowing developers to pass a result.
Description of change
#All Navigator methods have been updated to no longer call remove
but instead
use complete
. Context menus are now built from the contextMenuBuilder
parameter.
All methods that directly use complete
now accept an optional result
parameter to return it to the associated future. Other methods that indirectly
use remove
currently return null
. In the future, we might extend these
methods with an optional callback function to allow developers to handle pop
logic in indirect scenarios (such as removeUntil
).
Before this PR, methods bellow can't return a result :
Navigator.of(context).removeRoute(route);
Navigator.of(context).removeRouteBelow(route);
After this PR, methods can return a result :
Navigator.of(context).removeRoute(route, result);
Navigator.of(context).removeRouteBelow(route, result);
Migration guide
#If you implemented RouteTransitionRecord
and used markForRemove
,
you need to use markForComplete
instead. markForRemove
is now deprecated.
For other developers, no changes are required. The navigator continues to work as expected with new capabilities.
Timeline
#Landed in version: Not yet
In stable release: Not yet
References
#API documentation:
#Relevant issues:
#Relevant PRs:
#除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2025-02-12。 查看文档源码 或者 为本页面内容提出建议。