New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow gaps in the initial route #39440
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -783,6 +783,15 @@ class Navigator extends StatefulWidget { | |
/// then the [Navigator] would push the following routes on startup: `/`, | ||
/// `/stocks`, `/stocks/HOOLI`. This enables deep linking while allowing the | ||
/// application to maintain a predictable route history. | ||
/// | ||
/// If any of the intermediate routes doesn't exist, it'll simply be skipped. | ||
/// In the example above, if `/stocks` doesn't have a corresponding route in | ||
/// the app, it'll be skipped and only `/` and `/stocks/HOOLI` will be pushed. | ||
/// | ||
/// That said, the full route has to map to something in the app in order for | ||
/// this to work. In our example, `/stocks/HOOLI` has to map to a route in the | ||
/// app. Otherwise, [initialRoute] will be ignored and [defaultRouteName] will | ||
/// be used instead. | ||
final String initialRoute; | ||
|
||
/// Called to generate a route for a given [RouteSettings]. | ||
|
@@ -1509,9 +1518,6 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { | |
if (initialRouteName.startsWith('/') && initialRouteName.length > 1) { | ||
initialRouteName = initialRouteName.substring(1); // strip leading '/' | ||
assert(Navigator.defaultRouteName == '/'); | ||
final List<String> plannedInitialRouteNames = <String>[ | ||
Navigator.defaultRouteName, | ||
]; | ||
final List<Route<dynamic>> plannedInitialRoutes = <Route<dynamic>>[ | ||
_routeNamed<dynamic>(Navigator.defaultRouteName, allowNull: true, arguments: null), | ||
]; | ||
|
@@ -1520,30 +1526,25 @@ class NavigatorState extends State<Navigator> with TickerProviderStateMixin { | |
String routeName = ''; | ||
for (String part in routeParts) { | ||
routeName += '/$part'; | ||
plannedInitialRouteNames.add(routeName); | ||
plannedInitialRoutes.add(_routeNamed<dynamic>(routeName, allowNull: true, arguments: null)); | ||
} | ||
} | ||
if (plannedInitialRoutes.contains(null)) { | ||
if (plannedInitialRoutes.last == null) { | ||
assert(() { | ||
FlutterError.reportError( | ||
FlutterErrorDetails( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation on various |
||
exception: | ||
'Could not navigate to initial route.\n' | ||
'The requested route name was: "/$initialRouteName"\n' | ||
'The following routes were therefore attempted:\n' | ||
' * ${plannedInitialRouteNames.join("\n * ")}\n' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still use it below to push the routes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What line? Doesn't the pushing use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I misread your previous comment, thought you were talking about Yes, the variable |
||
'This resulted in the following objects:\n' | ||
' * ${plannedInitialRoutes.join("\n * ")}\n' | ||
'One or more of those objects was null, and therefore the initial route specified will be ' | ||
'There was no corresponding route in the app, and therefore the initial route specified will be ' | ||
'ignored and "${Navigator.defaultRouteName}" will be used instead.' | ||
), | ||
); | ||
return true; | ||
}()); | ||
push(_routeNamed<Object>(Navigator.defaultRouteName, arguments: null)); | ||
} else { | ||
plannedInitialRoutes.forEach(push); | ||
plannedInitialRoutes.where((Route<dynamic> route) => route != null).forEach(push); | ||
} | ||
} else { | ||
Route<Object> route; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exception message probably needs updating to reflect the new behavior?