copyWith method
NavigationCrossroad<T>
copyWith({
- T? activeBranch,
- Map<
T, NavigationStack< ? availableBranches,T> > - bool resetBranch = false,
- Object? branchParam,
Implementation
NavigationCrossroad<T> copyWith({
T? activeBranch,
Map<T, NavigationStack<T>>? availableBranches,
/// Resets the stack of the given branch.
/// Meaning it will be filled with default stack based on routes.
bool resetBranch = false,
Object? branchParam,
}) {
final tmp = NavigationCrossroad(
navigatorKey: navigatorKey,
navigatorKeys: navigatorKeys,
activeBranch: activeBranch ?? this.activeBranch,
availableBranches: availableBranches != null
? UnmodifiableMapView(availableBranches)
: this.availableBranches,
branchParam: branchParam ?? this.branchParam,
branchParams: branchParam != null
? branchParams.map(
(key, value) => MapEntry(
key,
key == (activeBranch ?? this.activeBranch)
? branchParam
: value,
),
)
: branchParams,
);
if (resetBranch) {
final branches = Map<T, NavigationStack<T>>.from(tmp.availableBranches);
/// When set to empty stack, it will be automatically filled.
branches[tmp.activeBranch] = NavigationStack([]);
return tmp.copyWith(availableBranches: branches);
}
return tmp;
}