From f36bc9afc11fafa65e4034a998ddfa3b87ccfb80 Mon Sep 17 00:00:00 2001 From: JulianAlcala Date: Wed, 15 Apr 2026 11:32:23 +0200 Subject: [PATCH] fix(router): unique navigatorKey per StatefulShellBranch to avoid duplicate GlobalKey crash --- .../mobile_app/lib/navigation/app_router.dart | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apps/mobile_app/lib/navigation/app_router.dart b/apps/mobile_app/lib/navigation/app_router.dart index b9787c5f..c8cc18b7 100644 --- a/apps/mobile_app/lib/navigation/app_router.dart +++ b/apps/mobile_app/lib/navigation/app_router.dart @@ -22,6 +22,25 @@ import 'package:splash/splash.dart'; final GlobalKey rootNavigatorKey = GlobalKey(); +final _legacyControlPanelNavKey = + GlobalKey(debugLabel: 'legacyControlPanel'); +final _legacyDeviceMgmtNavKey = + GlobalKey(debugLabel: 'legacyDeviceMgmt'); +final _legacyLocationNavKey = + GlobalKey(debugLabel: 'legacyLocation'); +final _legacyChatNavKey = GlobalKey(debugLabel: 'legacyChat'); +final _legacySettingsNavKey = + GlobalKey(debugLabel: 'legacySettings'); + +final _dashboardHomeNavKey = + GlobalKey(debugLabel: 'dashboardHome'); +final _dashboardActivityNavKey = + GlobalKey(debugLabel: 'dashboardActivity'); +final _dashboardNotificationsNavKey = + GlobalKey(debugLabel: 'dashboardNotifications'); +final _dashboardProfileNavKey = + GlobalKey(debugLabel: 'dashboardProfile'); + late final GoRouter appRouter; /// Maps the splash's session check result to the destination route based @@ -60,6 +79,7 @@ void configureAppRouter() { }, branches: [ StatefulShellBranch( + navigatorKey: _legacyControlPanelNavKey, routes: [ GoRoute( path: AppRoutes.controlPanel, @@ -108,6 +128,7 @@ void configureAppRouter() { ], ), StatefulShellBranch( + navigatorKey: _legacyDeviceMgmtNavKey, routes: [ GoRoute( path: AppRoutes.deviceManagement, @@ -181,6 +202,7 @@ void configureAppRouter() { ], ), StatefulShellBranch( + navigatorKey: _legacyLocationNavKey, routes: [ GoRoute( path: AppRoutes.legacyLocation, @@ -191,6 +213,7 @@ void configureAppRouter() { ), // TODO: AƱadir branch para Chat (tab 4) StatefulShellBranch( + navigatorKey: _legacyChatNavKey, routes: [ GoRoute( path: '${AppRoutes.legacyDashboard}/chat', @@ -205,6 +228,7 @@ void configureAppRouter() { ], ), StatefulShellBranch( + navigatorKey: _legacySettingsNavKey, routes: [ GoRoute( path: AppRoutes.settings, @@ -380,6 +404,7 @@ void configureAppRouter() { }, branches: [ StatefulShellBranch( + navigatorKey: _dashboardHomeNavKey, routes: [ GoRoute( path: AppRoutes.dashboardHome, @@ -448,6 +473,7 @@ void configureAppRouter() { ], ), StatefulShellBranch( + navigatorKey: _dashboardActivityNavKey, routes: [ GoRoute( path: AppRoutes.dashboardActivity, @@ -457,6 +483,7 @@ void configureAppRouter() { ], ), StatefulShellBranch( + navigatorKey: _dashboardNotificationsNavKey, routes: [ GoRoute( path: AppRoutes.dashboardNotifications, @@ -466,6 +493,7 @@ void configureAppRouter() { ], ), StatefulShellBranch( + navigatorKey: _dashboardProfileNavKey, routes: [ GoRoute( path: AppRoutes.dashboardProfile,