Migration guide for `RouteInformation.location`
Summary
#RouteInformation.location and related APIs were deprecated
in the favor of RouteInformation.uri.
Context
#The RouteInformation needs the authority information to
handle mobile deeplinks from different web domains.
The uri field was added to RouteInformation that captures
the entire deeplink information and route-related parameters
were converted to the full Uri format.
This led to deprecation of incompatible APIs.
Description of change
#- The
RouteInformation.locationwas replaced byRouteInformation.uri. - The
WidgetBindingObserver.didPushRoutewas deprecated. - The
locationparameter ofSystemNavigator.routeInformationUpdatedwas replaced by the newly addeduriparameter.
Migration guide
#Code before migration:
const RouteInformation myRoute = RouteInformation(location: '/myroute');Code after migration:
final RouteInformation myRoute = RouteInformation(uri: Uri.parse('/myroute'));Code before migration:
final String myPath = myRoute.location;Code after migration:
final String myPath = myRoute.uri.path;Code before migration:
class MyObserverState extends State<MyWidget> with WidgetsBindingObserver {
@override
Future<bool> didPushRoute(String route) => _handleRoute(route);
}Code after migration:
class MyObserverState extends State<MyWidget> with WidgetsBindingObserver {
@override
Future<bool> didPushRouteInformation(RouteInformation routeInformation) => _handleRoute(
Uri.decodeComponent(
Uri(
path: uri.path.isEmpty ? '/' : uri.path,
queryParameters: uri.queryParametersAll.isEmpty ? null : uri.queryParametersAll,
fragment: uri.fragment.isEmpty ? null : uri.fragment,
).toString(),
)
);
}Code before migration:
SystemNavigator.routeInformationUpdated(location: '/myLocation');Code after migration:
SystemNavigator.routeInformationUpdated(uri: Uri.parse('/myLocation'));Timeline
#Landed in version: 3.10.0-13.0.pre
In stable release: 3.13.0
References
#Relevant PRs:
- PR 119968: Implement url support for RouteInformation and didPushRouteInformation.
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2024-04-04。 查看文档源码 或者 为本页面内容提出建议.