remove method
Returns a new instance of RouteMatchList with the input match removed
from the current instance.
Implementation
RouteMatchList remove(RouteMatchBase match) {
final List<RouteMatchBase> newMatches = _removeRouteMatchFromList(matches, match);
if (newMatches == matches) {
return this;
}
final String fullPath = _generateFullPath(newMatches);
if (this.fullPath == fullPath) {
return copyWith(matches: newMatches);
}
if (newMatches.isEmpty) {
return RouteMatchList.empty;
}
RouteBase newRoute = newMatches.last.route;
while (newRoute is ShellRouteBase) {
newRoute = newRoute.routes.last;
}
newRoute as GoRoute;
// Need to remove path parameters that are no longer in the fullPath.
final newParameters = <String>[];
patternToRegExp(fullPath, newParameters, caseSensitive: newRoute.caseSensitive);
final Set<String> validParameters = newParameters.toSet();
final newPathParameters = Map<String, String>.fromEntries(
pathParameters.entries.where(
(MapEntry<String, String> value) => validParameters.contains(value.key),
),
);
final Uri newUri = uri.replace(path: patternToPath(fullPath, newPathParameters));
return copyWith(matches: newMatches, uri: newUri, pathParameters: newPathParameters);
}