switchToFeature method
Switches to feature, saving the current URI so it can be restored
when this feature is switched back to.
Implementation
void switchToFeature(FeatureNavigationConfiguration feature) {
try {
final router = _getRouter();
final navigator = _getMultilevelNavigator();
final currentUri = router.routerDelegate.currentConfiguration.uri;
final currentPath = currentUri.path;
final currentFeature = PathUtils.getFeatureConfiguration(
fullPath: currentPath,
featureConfigurations: navigator.allFeatures,
);
// Re-tapping the active feature in multi-column mode at depth >=3:
// toggle level2 if it's part of the current layout, otherwise open it
// by navigating to its path (e.g. a window showing only level1+level3).
final multilevelBloc = _maybeReadMultilevelBloc();
if (multilevelBloc != null && currentFeature?.key == feature.key) {
final multilevelState = multilevelBloc.state;
final depth = PathUtils.getPathDepth(multilevelState.path);
final isMultiColumn =
multilevelState.displayMode != DisplayMode.singleColumnWithBottomNav;
if (isMultiColumn && depth >= 3) {
if (!multilevelState.isLevel2InLayout) {
NavigationUtils.go(_getRouter(), feature.defaultLevel2Path);
} else {
toggleLevel2();
}
return;
}
}
NavigationUtils.switchToFeature(
router,
navigator.navigationStorage,
featureKey: feature.key,
defaultPath: feature.defaultLevel2Path,
currentFeatureKey: currentFeature?.key,
);
} catch (e) {
debugPrint('[ContextNavigationExtensions] Error in switchToFeature: $e');
rethrow;
}
}