-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Closed
Labels
in triagePresently being triaged by the triage teamPresently being triaged by the triage teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
Description
The code below has been working without issues for all the devices previously tested on, both iOS and Android. However, recently on Flutter v.2.10.5 on an physical iPhone 13 iOS 15.4 I get a 'Multiple widgets used the same GlobalKey' error with the code shown below. For other iOS and Android devices the code continues to work fine.
From the error it looks like two versions of the same widget exists causing the error, but I am not quite sure why that would happen?
Flutter code:
final PageStorageBucket _bucket = PageStorageBucket();
final GlobalKey bottomNavigationBarKey = GlobalKey(debugLabel: 'barKey');
double? _navigationBarHeight;
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageStorage(
child: pages[_selectedIndex],
bucket: _bucket,
),
bottomNavigationBar: AnimatedContainer(
duration: const Duration(milliseconds: 300),
height: _navigationBarHeight
child: SingleChildScrollView(
child: SafeArea(
child: SizedBox(
height: 55.0,
child: BottomNavigationBar(
// Global key added here
key: bottomNavigationBarKey,
items: ...
),
),
),
),
),
),
}
Error message:
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while finalizing the widget tree:
Multiple widgets used the same GlobalKey.
The key [GlobalKey#9e720 barKey] was used by multiple widgets. The parents of those widgets were:
- SizedBox(height: 55.0, renderObject: RenderConstrainedBox#9f47f relayoutBoundary=up3)
- SizedBox(height: 55.0, renderObject: RenderConstrainedBox#25bf8 relayoutBoundary=up3 NEEDS-PAINT)
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/…/widgets/framework.dart:2868
#1 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:539:8)
#2 BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure>.<anonymous closure>
package:flutter/…/widgets/framework.dart:2815
#3 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:539:8)
#4 BuildOwner._debugVerifyGlobalKeyReservation.<anonymous closure>
package:flutter/…/widgets/framework.dart:2811
#5 BuildOwner._debugVerifyGlobalKeyReservation
package:flutter/…/widgets/framework.dart:2876
#6 BuildOwner.finalizeTree.<anonymous closure>
package:flutter/…/widgets/framework.dart:2935
#7 BuildOwner.finalizeTree
package:flutter/…/widgets/framework.dart:3016
#8 WidgetsBinding.drawFrame
package:flutter/…/widgets/binding.dart:884
#9 RendererBinding._handlePersistentFrameCallback
package:flutter/…/rendering/binding.dart:363
#10 SchedulerBinding._invokeFrameCallback
package:flutter/…/scheduler/binding.dart:1144
#11 SchedulerBinding.handleDrawFrame
package:flutter/…/scheduler/binding.dart:1081
#12 SchedulerBinding._handleDrawFrame
package:flutter/…/scheduler/binding.dart:995
#16 _invoke (dart:ui/hooks.dart:151:10)
#17 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#18 _drawFrame (dart:ui/hooks.dart:115:31)
(elided 3 frames from dart:async)
════════════════════════════════════════════════════════════════════════════════
Flutter doctor -v
[✓] Flutter (Channel stable, 2.10.5, on macOS 12.3.1 21E258 darwin-arm)
• Flutter version 2.10.5
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 5464c5bac7 (7 days ago), 2022-04-18 09:55:37 -0700
• Engine revision 57d3bac3dd
• Dart version 2.16.2
• DevTools version 2.9.2
[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3
[✓] VS Code (version 1.66.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.38.1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
in triagePresently being triaged by the triage teamPresently being triaged by the triage teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds