iOS Development

android – One other exception was thrown: Duplicate GlobalKey detected in widget tree – StatefulShellRoute

Spread the love


I attempted so as to add route transition animation with AnimatedSwitcher to StatefulShellRoute.indexedStack however received this error:

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The next assertion was thrown whereas finalizing the widget tree:
flutter: Duplicate GlobalKey detected in widget tree.
flutter: The next GlobalKey was specified a number of instances within the widget tree. This may result in components of
flutter: the widget tree being truncated unexpectedly, as a result of the second time a key's seen, the earlier
flutter: occasion is moved to the brand new location. The important thing was:
flutter: - [LabeledGlobalKey<StatefulNavigationShellState>#c2de3]
flutter: This was decided by noticing that after the widget with the above international key was moved out of its
flutter: earlier father or mother, that earlier father or mother by no means up to date throughout this body, which means that it both did
flutter: not replace in any respect or up to date earlier than the widget was moved, in both case implying that it nonetheless
flutter: thinks that it ought to have a toddler with that international key.
flutter: The precise father or mother that didn't replace after having a number of youngsters forcibly eliminated as a consequence of
flutter: GlobalKey reparenting is:
flutter: - SizedBox-[<'0'>](renderObject: RenderConstrainedBox#33176 relayoutBoundary=up4)
flutter: A GlobalKey can solely be specified on one widget at a time within the widget tree.
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      BuildOwner.finalizeTree.<nameless closure> (bundle:flutter/src/widgets/framework.dart:3109:15)
flutter: #1      BuildOwner.finalizeTree (bundle:flutter/src/widgets/framework.dart:3134:8)
flutter: #2      WidgetsBinding.drawFrame (bundle:flutter/src/widgets/binding.dart:919:19)
flutter: #3      RendererBinding._handlePersistentFrameCallback (bundle:flutter/src/rendering/binding.dart:360:5)
flutter: #4      SchedulerBinding._invokeFrameCallback (bundle:flutter/src/scheduler/binding.dart:1297:15)
flutter: #5      SchedulerBinding.handleDrawFrame (bundle:flutter/src/scheduler/binding.dart:1227:9)
flutter: #6      SchedulerBinding._handleDrawFrame (bundle:flutter/src/scheduler/binding.dart:1085:5)
flutter: #7      _invoke (dart:ui/hooks.dart:170:13)
flutter: #8      PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:401:5)
flutter: #9      _drawFrame (dart:ui/hooks.dart:140:31)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: One other exception was thrown: Duplicate GlobalKey detected in widget tree.

Code:

return Scaffold(
  physique: AnimatedSwitcher(
    period: const Length(milliseconds: 500),
    switchInCurve: Curves.ease,
    switchOutCurve: Curves.ease,
    youngster: SizedBox(
      key: Key(navigationShell.currentIndex.toString()),
      youngster: navigationShell,
    ),
  ),
  ....

Each time I name navigationShell.goBranch I get this error:

flutter: One other exception was thrown: Duplicate GlobalKey detected in widget tree.

I would like there to be a web page transition animation. I could not discover any options.

Leave a Reply

Your email address will not be published. Required fields are marked *