getPathFromPop method
VPopResult
getPathFromPop(
- VRouteElement elementToPop, {
- required Map<
String, String> pathParameters, - required GetNewParentPathResult parentPathResult,
override
VPopResult.didPop
is true if this VRouteElement popped
VPopResult.extendedPath
is null if this path can't be the right one according to
the path parameters
VPopResult is null when this VRouteElement does not pop AND none of
its stackedRoutes popped
Implementation
VPopResult getPathFromPop(
VRouteElement elementToPop, {
required Map<String, String> pathParameters,
required GetNewParentPathResult parentPathResult,
}) {
// If vRouteElement is this, then this is the element to pop so we return null
if (elementToPop == this) {
return PoppingPopResult(poppedVRouteElements: [this]);
}
// Try to pop from the nestedRoutes
for (var vRouteElement in nestedRoutes) {
VPopResult childPopResult = vRouteElement.getPathFromPop(
elementToPop,
pathParameters: pathParameters,
parentPathResult: parentPathResult,
);
if (!(childPopResult is NotFoundPopResult)) {
// If the VRouteElement to pop has been found
// If NOT PoppingPopResult, return the PathParamsPopErrors or the ValidPopResult as is
if (!(childPopResult is PoppingPopResult)) {
return childPopResult;
}
// If nestedRoute returned PoppingPopResult, we should pop too
// Add ourselves to the poppedVRouteElements in a PoppingPopResult
return PoppingPopResult(
poppedVRouteElements: childPopResult.poppedVRouteElements + [this],
);
}
}
// Try to pop from the subRoutes
for (var vRouteElement in stackedRoutes) {
VPopResult childPopResult = vRouteElement.getPathFromPop(
elementToPop,
pathParameters: pathParameters,
parentPathResult: parentPathResult,
);
if (!(childPopResult is NotFoundPopResult)) {
// If the VRouteElement to pop has been found
// If NOT PoppingPopResult, return the PathParamsPopErrors or the ValidPopResult as is
if (!(childPopResult is PoppingPopResult)) {
// If it is ValidPopResult, add this name to the list of names if this has a name
if (childPopResult is ValidPopResult) {
return ValidPopResult(
path: childPopResult.path,
poppedVRouteElements: childPopResult.poppedVRouteElements,
names:
(name != null ? [name!] : <String>[]) + childPopResult.names,
);
}
return childPopResult;
}
// We should NOT pop with the VRouteElement to pop
final poppedVRouteElements =
childPopResult.poppedVRouteElements + [this];
// Check whether the parentPathResult is valid or not
if (parentPathResult is ValidParentPathResult) {
// If parentPathResult is valid, return a ValidPopResult with the right path
return ValidPopResult(
path: parentPathResult.path,
poppedVRouteElements: poppedVRouteElements,
names: name != null ? [name!] : [],
);
}
// Else return a PathParamsPopErrors by specifying what prevented parentPathResult from
// being valid
assert(parentPathResult is PathParamsErrorNewParentPath);
return PathParamsPopErrors(
poppedVRouteElements: poppedVRouteElements,
values: [
MissingPathParamsError(
pathParams: pathParameters.keys.toList(),
missingPathParams:
(parentPathResult as PathParamsErrorNewParentPath)
.pathParameters,
),
],
);
}
}
// If none of the stackedRoutes popped and this did not pop, return a NotValidPopResult
// This should never reach RootVRouter
return NotFoundPopResult();
}