copyWithNestedStack method
Replaces the active pages stack on the given nesting level.
nestingLevel
of 0 is the current node's nestedNodes active stack.
Implementation
AppPageNode<T> copyWithNestedStack(
List<AppPageNode<T>> stack, int nestingLevel) {
if (crossroad == null) {
throw Exception('This app page node is not a navigation crossroad');
}
final activeBranch = crossroad!.activeBranchStack;
final res = Map<T, NavigationStack<T>>.of(crossroad!.availableBranches);
if (nestingLevel == 0) {
res[crossroad!.activeBranch] = NavigationStack(stack);
} else {
res[crossroad!.activeBranch] = NavigationStack([
...activeBranch.pageNodesStack
.take(res[crossroad!.activeBranch]!.pageNodesStack.length - 1),
activeBranch.pageNodesStack.last
.copyWithNestedStack(stack, nestingLevel - 1),
]);
}
return copyWith(crossroad: crossroad!.copyWith(availableBranches: res));
}