I'm getting the following error thrown randomly (in Flutter Web) and unfortunately, I can't ping it to any recent change I have done. E.g. I can navigate between the dashboard screen and the blog screen as often as I want, but if I refresh the page while the blog screen is opened, it's thrown immediately.
======== Exception caught by widgets library =======================================================
The following assertion was thrown while finalizing the widget tree:
Multiple widgets used the same GlobalKey.
The key [LabeledGlobalKey<NavigatorState>#bf785 shell] was used by multiple widgets. The parents of those widgets were:
- KeyedSubtree-[GlobalKey#44343]
- KeyedSubtree-[GlobalKey#b6c01]
A GlobalKey can only be specified on one widget at a time in the widget tree.
When the exception was thrown, this was the stack:
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw_
packages/flutter/src/widgets/framework.dart 2883:13 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13 forEach
packages/flutter/src/widgets/framework.dart 2827:19 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13 forEach
packages/flutter/src/widgets/framework.dart 2822:36 <fn>
packages/flutter/src/widgets/framework.dart 2890:14 [_debugVerifyGlobalKeyReservation]
packages/flutter/src/widgets/framework.dart 2950:11 <fn>
packages/flutter/src/widgets/framework.dart 3031:16 finalizeTree
packages/flutter/src/widgets/binding.dart 885:7 drawFrame
packages/flutter/src/rendering/binding.dart 378:5 [_handlePersistentFrameCallback]
packages/flutter/src/scheduler/binding.dart 1175:15 [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1104:9 handleDrawFrame
packages/flutter/src/scheduler/binding.dart 1015:5 [_handleDrawFrame]
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 1168:13 invoke
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 219:5 invokeOnDrawFrame
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/initialization.dart 195:45 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334:14 _checkAndCall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 339:39 dcall
====================================================================================================
How can I find out which widgets are causing this issue? The only location I use global keys is in the router like so:
final GlobalKey<NavigatorState> _rootNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'root');
final GlobalKey<NavigatorState> _shellNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'shell');
final routerProvider = Provider<GoRouter>((ref) {
final authState = ref.watch(authProvider);
return GoRouter(
navigatorKey: _rootNavigatorKey,
//debugLogDiagnostics: true,
initialLocation: SplashScreen.routeLocation,
routes: [
GoRoute(
path: SplashScreen.routeLocation,
name: SplashScreen.routeName,
builder: (context, state) {
return DeepLinkWrapper(child: const SplashScreen());
},
),
ShellRoute(
navigatorKey: _shellNavigatorKey,
builder: (BuildContext context, GoRouterState state, Widget child) {
return MyCustomShell(
child: child,
);
},
routes: [
GoRoute(
path: DashboardScreenWeb.routeLocation,
name: DashboardScreenWeb.routeName,
builder: (context, state) {
return DeepLinkWrapper(child: DashboardScreenWeb());
},
),
GoRoute(
path: BlogScreen.routeLocation,
name: BlogScreen.routeName,
builder: (context, state) {
return DeepLinkWrapper(child: BlogScreen(blogId: state.params['blogId']!));
},
),
...
]
]
)
};