parseRouteInformation method
Converts the given route information into parsed data to pass to a RouterDelegate.
The method should return a future which completes when the parsing is complete. The parsing may be asynchronous if, e.g., the parser needs to communicate with the OEM thread to obtain additional data about the route.
Consider using a SynchronousFuture if the result can be computed synchronously, so that the Router does not need to wait for the next microtask to pass the data to the RouterDelegate.
One can implement parseRouteInformationWithDependencies instead if the parsing depends on other dependencies from the BuildContext.
Implementation
@override
Future<RouterConfiguration> parseRouteInformation(
RouteInformation routeInformation,
) async {
final uri = routeInformation.uri;
if (uri.pathSegments.isEmpty) {
return SynchronousFuture(
[const RouteSettings(name: '/')],
);
}
final paths = uri.pathSegments.map((e) => "/$e");
final args = uri.queryParameters;
String currentPath = "";
final config = [
const RouteSettings(name: '/'),
for (final path in paths)
() {
currentPath += path;
return RouteSettings(
name: currentPath,
arguments: paths.last == path ? args : null,
);
}.call()
];
return SynchronousFuture(config);
}