Repository navigation
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.5Found to occur in 3.5Found to occur in 3.5has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagescupertino_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Description
Steps to Reproduce
- Execute
flutter runon the code sample - Click the settings icon button in the app bar
Expected results:
No error gets thrown, since doing the same with the equivalent material widgets (Scaffold, AppBar) throws no such error.
Actual results:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY
╞═══════════════════════════════════════════════════════════
The following assertion was thrown while finalizing the widget tree:
Multiple widgets used the same GlobalKey.
The key [GlobalKey#cf59a] was used by multiple widgets. The parents of those
widgets were different
widgets that both had the following description:
IconTheme(color: systemBlue)
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:
#0 BuildOwner._debugVerifyGlobalKeyReservation.<anonymous
closure>.<anonymous closure>.<anonymous closure>
(package:flutter/src/widgets/framework.dart:2883:13)
#1 _LinkedHashMapMixin.forEach
(dart:collection-patch/compact_hash.dart:617:13)
#2 BuildOwner._debugVerifyGlobalKeyReservation.<anonymous
closure>.<anonymous closure>
(package:flutter/src/widgets/framework.dart:2827:20)
#3 _LinkedHashMapMixin.forEach
(dart:collection-patch/compact_hash.dart:617:13)
#4 BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure>
(package:flutter/src/widgets/framework.dart:2822:36)
#5 BuildOwner._debugVerifyGlobalKeyReservation
(package:flutter/src/widgets/framework.dart:2891:6)
#6 BuildOwner.finalizeTree.<anonymous closure>
(package:flutter/src/widgets/framework.dart:2950:11)
#7 BuildOwner.finalizeTree
(package:flutter/src/widgets/framework.dart:3032:8)
#8 WidgetsBinding.drawFrame
(package:flutter/src/widgets/binding.dart:885:19)
#9 RendererBinding._handlePersistentFrameCallback
(package:flutter/src/rendering/binding.dart:378:5)
#10 SchedulerBinding._invokeFrameCallback
(package:flutter/src/scheduler/binding.dart:1175:15)
#11 SchedulerBinding.handleDrawFrame
(package:flutter/src/scheduler/binding.dart:1104:9)
#12 SchedulerBinding._handleDrawFrame
(package:flutter/src/scheduler/binding.dart:1015:5)
#13 _invoke (dart:ui/hooks.dart:148:13)
#14 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5)
#15 _drawFrame (dart:ui/hooks.dart:115:31)
════════════════════════════════════════════════════════════════════════════════
════════════════════
Another exception was thrown: Multiple widgets used the same GlobalKey.
Another exception was thrown: Multiple widgets used the same GlobalKey.
Another exception was thrown: Duplicate GlobalKey detected in widget tree.
Code sample
import 'package:flutter/cupertino.dart';
void main() => runApp(const CupertinoApp(home: Example()));
class Example extends StatelessWidget {
const Example({Key? key}) : super(key: key);
static final GlobalKey settingsButtonKey = GlobalKey();
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: Container(),
navigationBar: CupertinoNavigationBar(
trailing: CupertinoButton(
onPressed: () {
Navigator.push(context, CupertinoPageRoute(builder: (context) => const SettingsPage()));
},
child: const Icon(CupertinoIcons.settings),
key: settingsButtonKey,
)),
);
}
}
class SettingsPage extends StatelessWidget {
const SettingsPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: Container(),
navigationBar: const CupertinoNavigationBar(middle: Text("Settings")),
);
}
}Logs
[ ] R Hot restart.
[ ] h List all available interactive commands.
[ ] d Detach (terminate "flutter run" but leave application running).
[ ] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ ] Running with sound null safety
[ ] An Observatory debugger and profiler on Pixel 3a is available at: http://127.0.0.1:60024/yUcbevZ8ywM=/
[ +557 ms] The Flutter DevTools debugger and profiler on Pixel 3a is available at: http://127.0.0.1:9100?uri=http://127.0.0.1:60024/yUcbevZ8ywM=/
[+6800 ms]
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown while finalizing the widget tree:
Multiple widgets used the same GlobalKey.
The key [GlobalKey#cf82d] was used by multiple widgets. The parents of those widgets were different
widgets that both had the following description:
IconTheme(color: systemBlue)
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:
#0 BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/widgets/framework.dart:2883:13)
#1 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:617:13)
#2 BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure>.<anonymous closure> (package:flutter/src/widgets/framework.dart:2827:20)
#3 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:617:13)
#4 BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure> (package:flutter/src/widgets/framework.dart:2822:36)
#5 BuildOwner._debugVerifyGlobalKeyReservation (package:flutter/src/widgets/framework.dart:2891:6)
#6 BuildOwner.finalizeTree.<anonymous closure> (package:flutter/src/widgets/framework.dart:2950:11)
#7 BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:3032:8)
#8 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:885:19)
#9 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:378:5)
#10 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
#11 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104:9)
#12 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1015:5)
#13 _invoke (dart:ui/hooks.dart:148:13)
#14 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5)
#15 _drawFrame (dart:ui/hooks.dart:115:31)
════════════════════════════════════════════════════════════════════════════════════════════════════
No issues found! (ran in 7.5s)
[√] Flutter (Channel stable, 3.3.4, on Microsoft Windows [Version 10.0.19044.2130], locale de-DE)
• Flutter version 3.3.4 on channel stable at D:\Programme\Flutter\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision eb6d86ee27 (9 days ago), 2022-10-04 22:31:45 -0700
• Engine revision c08d7d5efc
• Dart version 2.18.2
• DevTools version 2.15.0
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc4)
• Android SDK at D:\Programme\AndroidSDK
• Platform android-33, build-tools 31.0.0-rc4
• ANDROID_HOME = D:\Programme\AndroidSDK
• ANDROID_SDK_ROOT = D:\Programme\AndroidSDK
• Java binary at: D:\Programme\AndroidStudio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[!] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.7)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
• Visual Studio Build Tools 2019 version 16.11.31911.196
• Windows 10 SDK version 10.0.19041.0
X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components:
MSVC v142 - VS 2019 C++ x64/x86 build tools
- If there are multiple build tool versions available, install the latest
C++ CMake tools for Windows
Windows 10 SDK
[√] Android Studio (version 2021.2)
• Android Studio at D:\Programme\AndroidStudio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
[√] IntelliJ IDEA Community Edition (version 2020.2)
• IntelliJ at D:\Programme\IntelliJ IDEA Community Edition 2020.2
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
[√] Connected device (4 available)
• Pixel 3a (mobile) • 98XAY17YMW • android-arm64 • Android 12 (API 32)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19044.2130]
• Chrome (web) • chrome • web-javascript • Google Chrome 106.0.5249.119
• Edge (web) • edge • web-javascript • Microsoft Edge 106.0.1370.42
[√] HTTP Host Availability
• All required HTTP hosts are available
Reacted by Sudip Das
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: routesNavigator, Router, and related APIs.Navigator, Router, and related APIs.found in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.5Found to occur in 3.5Found to occur in 3.5has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagescupertino_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Activity
[-]GlobalKey in CupertinoNavigationBar triggers "Multiple widgets used the same GlobalKey." when changing route[/-][+]GlobalKey in CupertinoNavigationBar property triggers "Multiple widgets used the same GlobalKey." when changing route[/+]danagbemava-nc commentedon Oct 14, 2022
The issue is reproducible using the code sample provided above.
Adding the key to the
CupertinoNavigationBaritself does not trigger the exception. It seems to be triggered when the key is added to a property of theCupertinoNavigationBar.I tested with
leading,trailing&middle, and the exception was thrown for all 3 properties.Labeling for further investigation from the team.
logs
flutter doctor -v
MitchellGoodwin commentedon Nov 11, 2022
This is a known limitation of
CupertinoNavigationBarbecause on the slide transition, a new nav bar is painted over the existing one, with the child widgets copied over. See the paragraph on transitionBetweenRoutes for more information, and work arounds.However from this issue, and the duplicate one, it does seem like there's a need to be adjusted, but it will be a fairly sizable rewrite of the transition, so it may not be a quick fix.
1 remaining item
flutter-triage-bot commentedon Jul 8, 2023
This issue is assigned but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!
MitchellGoodwin commentedon Aug 18, 2023
I'm downgrading the priority to p2 as per my last comment. I'm also unassigning this from myself as I'm not actively working on this at the moment. If somebody wants to pick it up before I get to it, please feel free to tag me here or on Discord for help.
victorsanni commentedon Jun 6, 2025
As a workaround, set
CupertinoNavigationBar.transitionBetweenRoutesorCupertinoSliverNavigationBar.transitionBetweenRoutesto false.test: canary for a GlobalKey in a Cupertino bar on a push (flutter/fl…