Repository: flutter
Issue: GlobalKey in CupertinoNavigationBar property triggers "Multiple widgets used the same GlobalKey." when changing route
Labels: framework,f: cupertino,f: routes,has reproducible steps,P2,found in release: 3.3,found in release: 3.5,team-design,triaged-design

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->

1. Execute `flutter run` on the code sample <!-- (see "Code sample" section below) -->
2. Click the settings icon button in the app bar

**Expected results:** <!-- what did you want to see? -->
No error gets thrown, since doing the same with the equivalent material widgets (Scaffold, AppBar) throws no such error.

**Actual results:** <!-- what did you see? -->
```
══╡ 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.
```


<details>
<summary>Code sample</summary>

<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->

```dart
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")),
    );
  }
}
```

</details>

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue. If there is a crash, please include
      the entirety of the crash log including the backtrace.
-->

```
[        ] 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)
                    ════════════════════════════════════════════════════════════════════════════════════════════════════

```

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
No issues found! (ran in 7.5s)
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[√] 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
```

</details>


<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->