build method
Implementation
RoutePath build(String path, Uri uri) {
// Adjust the path according to the pattern
var subPath = pattern.allMatches(path).first.group(1);
// Return not found if no sub path is found
if (subPath == null) return bareBuilder('', notFoundScreen)();
// Look for a matchin sub path
var subPathsBuilder = paths.firstWhere(
(o) => o.pattern.hasMatch(subPath),
orElse: () => this,
);
// Use sub path if matched
if (subPathsBuilder != this) {
return subPathsBuilder.build(subPath, uri);
} else {
// Look for a mathcing builder
var builder = builders.firstWhere(
(o) => o.pattern.hasMatch(subPath),
orElse: () => bareBuilder(subPath, notFoundScreen),
);
// Collect the segments for the path
RouteSegments segments;
var match = builder.pattern.firstMatch(subPath);
if (match == null) {
segments = {};
} else {
var groupNames = match.groupNames.map((o) => [o, match.namedGroup(o)]);
segments = {for (var o in groupNames) '${o[0]}': o[1]};
}
// Build and return the route path
return builder(segments, uri.queryParametersAll);
}
}