NavigationCrossroad<T> constructor
NavigationCrossroad<T> ({
- required T activeBranch,
- Map<
T, NavigationStack< ? availableBranches,T> > - Object? branchParam,
- Map<
T, Object?> ? branchParams,
Implementation
NavigationCrossroad({
required this.activeBranch,
Map<T, NavigationStack<T>>? availableBranches,
GlobalKey<NavigatorState>? navigatorKey,
Map<T, GlobalKey<NavigatorState>>? navigatorKeys,
this.branchParam,
Map<T, Object?>? branchParams,
}) : availableBranches = UnmodifiableMapView(availableBranches ?? {}),
navigatorKey = navigatorKey ?? GlobalKey<NavigatorState>() {
this.branchParams = UnmodifiableMapView(
branchParams != null
? {
...branchParams,
...Map.fromEntries(this
.availableBranches
.keys
.toSet()
.difference(branchParams.keys.toSet())
.map((e) => MapEntry(e, null))),
}
: Map.fromEntries(
this.availableBranches.keys.map((e) => MapEntry(e, null))),
);
assert(() {
if (this.branchParams.length != this.availableBranches.length) {
throw NavigationStackError(
'branchParams list needs to have the size equal to the branches count');
}
return true;
}());
this.navigatorKeys = UnmodifiableMapView(
navigatorKeys != null
? {
...navigatorKeys,
...Map.fromEntries(this
.availableBranches
.keys
.toSet()
.difference(navigatorKeys.keys.toSet())
.map((e) => MapEntry(e, GlobalKey<NavigatorState>()))),
}
: Map.fromEntries(
this.availableBranches.keys.map(
(e) => MapEntry(e, GlobalKey<NavigatorState>()),
),
),
);
assert(() {
if (!setEquals(this.navigatorKeys.keys.toSet(),
this.availableBranches.keys.toSet())) {
throw NavigationStackError(
'There are missing keys for in the navigatorKeys. '
'It has to match the same branches as in availableBranches.');
}
return true;
}());
}