fix(router): unique navigatorKey per StatefulShellBranch to avoid duplicate GlobalKey crash

This commit is contained in:
2026-04-15 11:32:23 +02:00
parent 95a03434ca
commit f36bc9afc1

View File

@@ -22,6 +22,25 @@ import 'package:splash/splash.dart';
final GlobalKey<NavigatorState> rootNavigatorKey = GlobalKey<NavigatorState>();
final _legacyControlPanelNavKey =
GlobalKey<NavigatorState>(debugLabel: 'legacyControlPanel');
final _legacyDeviceMgmtNavKey =
GlobalKey<NavigatorState>(debugLabel: 'legacyDeviceMgmt');
final _legacyLocationNavKey =
GlobalKey<NavigatorState>(debugLabel: 'legacyLocation');
final _legacyChatNavKey = GlobalKey<NavigatorState>(debugLabel: 'legacyChat');
final _legacySettingsNavKey =
GlobalKey<NavigatorState>(debugLabel: 'legacySettings');
final _dashboardHomeNavKey =
GlobalKey<NavigatorState>(debugLabel: 'dashboardHome');
final _dashboardActivityNavKey =
GlobalKey<NavigatorState>(debugLabel: 'dashboardActivity');
final _dashboardNotificationsNavKey =
GlobalKey<NavigatorState>(debugLabel: 'dashboardNotifications');
final _dashboardProfileNavKey =
GlobalKey<NavigatorState>(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,