Skip to content

Failed assertion: line 5241 pos 14: '_dependents.isEmpty': is not true. #99689

@alaxcc

Description

@alaxcc

Steps to Reproduce

  1. Execute flutter run to default Page Login.dart
  2. Click Sign in with token and Navigator to Home.dart.
  3. Click Logout button to navigator to Login.dart
  4. Click Sign in with different token and Navigator to Home.dart.
    Expected results:
    display normal and no error logs.
    Actual results:

white screen and error log:

Code sample
body: WillPopScope(
        onWillPop: () async {
          if (app.navigatorKey.currentState != null && app.navigatorKey.currentState!.canPop()) {
            app.navigatorKey.currentState!.pop();
            return false;
          }
          return true;
        },
        child: Navigator(
          key: app.navigatorKey,
          initialRoute: '/',
          onGenerateRoute: (RouteSettings settings) {
            WidgetBuilder builder = routes[settings.name]!;
            // Manage your route names here

            Future.delayed(Duration(milliseconds: 100)).then((value) => updateState(settings.name));



            // You can also return a PageRouteBuilder and
            // define custom transitions between pages
            return MaterialPageRoute(
              builder: builder,
              settings: settings,
            );
          },
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(...)
Logs



======== Exception caught by widgets library =======================================================
The following assertion was thrown building WillPopScope(dependencies: [_ModalScopeStatus], state: _WillPopScopeState#27f1e):
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5241 pos 14: '_dependents.isEmpty': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was: 
  WillPopScope WillPopScope:file:///E:/front/project_flutter_crm/lib/view/home.dart:53:13
When the exception was thrown, this was the stack: 
#2      InheritedElement.debugDeactivated.<anonymous closure> (package:flutter/src/widgets/framework.dart:5241:14)
#3      InheritedElement.debugDeactivated (package:flutter/src/widgets/framework.dart:5243:6)
#4      _InactiveElements._deactivateRecursively.<anonymous closure> (package:flutter/src/widgets/framework.dart:2000:15)
#5      _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2002:6)
#6      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4845:14)
#7      _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:1998:13)
#8      SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6288:14)
#9      _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:1998:13)
#10     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4845:14)
#11     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:1998:13)
#12     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6288:14)
#13     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:1998:13)
#14     SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6288:14)
#15     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:1998:13)
#16     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4845:14)
#17     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:1998:13)
#18     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4845:14)
#19     _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:1998:13)
#20     _InactiveElements.add (package:flutter/src/widgets/framework.dart:2010:7)
#21     Element.deactivateChild (package:flutter/src/widgets/framework.dart:3863:30)
#22     Element._retakeInactiveElement (package:flutter/src/widgets/framework.dart:3763:14)
...     Normal element mounting (27 frames)
#49     Element.inflateWidget (package:flutter/src/widgets/framework.dart:3823:14)
#50     MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6436:36)
#51     MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6448:32)
...     Normal element mounting (263 frames)
#314    Element.inflateWidget (package:flutter/src/widgets/framework.dart:3823:14)
#315    MultiChildRenderObjectElement.inflateWidget (package:flutter/src/widgets/framework.dart:6436:36)
#316    Element.updateChild (package:flutter/src/widgets/framework.dart:3562:18)
#317    RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5865:32)
#318    MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6461:17)
#319    Element.updateChild (package:flutter/src/widgets/framework.dart:3541:15)
#320    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4818:16)
#321    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4963:11)
#322    Element.rebuild (package:flutter/src/widgets/framework.dart:4515:5)
#323    StatefulElement.update (package:flutter/src/widgets/framework.dart:4995:5)
#324    Element.updateChild (package:flutter/src/widgets/framework.dart:3541:15)
#325    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4818:16)
#326    Element.rebuild (package:flutter/src/widgets/framework.dart:4515:5)
#327    ProxyElement.update (package:flutter/src/widgets/framework.dart:5140:5)
#328    Element.updateChild (package:flutter/src/widgets/framework.dart:3541:15)
#329    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4818:16)
#330    Element.rebuild (package:flutter/src/widgets/framework.dart:4515:5)
#331    ProxyElement.update (package:flutter/src/widgets/framework.dart:5140:5)
#332    _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:108:11)
#333    Element.updateChild (package:flutter/src/widgets/framework.dart:3541:15)
#334    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6308:14)
#335    Element.updateChild (package:flutter/src/widgets/framework.dart:3541:15)
#336    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4818:16)
#337    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4963:11)
#338    Element.rebuild (package:flutter/src/widgets/framework.dart:4515:5)
#339    StatefulElement.update (package:flutter/src/widgets/framework.dart:4995:5)
#340    Element.updateChild (package:flutter/src/widgets/framework.dart:3541:15)
#341    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6308:14)
#342    Element.updateChild (package:flutter/src/widgets/framework.dart:3541:15)
#343    SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6308:14)
#344    Element.updateChild (package:flutter/src/widgets/framework.dart:3541:15)
#345    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4818:16)
#346    Element.rebuild (package:flutter/src/widgets/framework.dart:4515:5)
#347    ProxyElement.update (package:flutter/src/widgets/framework.dart:5140:5)
#348    Element.updateChild (package:flutter/src/widgets/framework.dart:3541:15)
#349    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4818:16)
#350    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4963:11)
#351    Element.rebuild (package:flutter/src/widgets/framework.dart:4515:5)
#352    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2713:19)
#353    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#354    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:367:5)
#355    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#356    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#357    SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#361    _invoke (dart:ui/hooks.dart:151:10)
#362    PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#363    _drawFrame (dart:ui/hooks.dart:115:31)
(elided 5 frames from class _AssertionError and dart:async)
====================================================================================================

======== Exception caught by widgets library =======================================================
The following assertion was thrown while finalizing the widget tree:
Duplicate GlobalKey detected in widget tree.

The following GlobalKey was specified multiple times in the widget tree. This will lead to parts of the widget tree being truncated unexpectedly, because the second time a key is seen, the previous instance is moved to the new location. The key was:
- [LabeledGlobalKey<NavigatorState>#d402b]
This was determined by noticing that after the widget with the above global key was moved out of its previous parent, that previous parent never updated during this frame, meaning that it either did not update at all or updated before the widget was moved, in either case implying that it still thinks that it should have a child with that global key.
The specific parent that did not update after having one or more children forcibly removed due to GlobalKey reparenting is:
- WillPopScope(dependencies: [_ModalScopeStatus], state: _WillPopScopeState#7ce4a)
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.finalizeTree.<anonymous closure> (package:flutter/src/widgets/framework.dart:3045:15)
#1      BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:3070:8)
#2      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:884:19)
#3      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:367:5)
#4      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#5      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#6      SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#10     _invoke (dart:ui/hooks.dart:151:10)
#11     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#12     _drawFrame (dart:ui/hooks.dart:115:31)
(elided 3 frames from dart:async)
====================================================================================================

======== Exception caught by scheduler library =====================================================
The following assertion was thrown during a scheduler callback:
Tried to build dirty widget in the wrong build scope.

A widget which was marked as dirty and is still active was scheduled to be built, but the current build scope unexpectedly does not contain that widget.

Sometimes this is detected when an element is removed from the widget tree, but the element somehow did not get marked as inactive. In that case, it might be caused by an ancestor element failing to implement visitChildren correctly, thus preventing some or all of its descendants from being correctly deactivated.

The root of the build scope was: [root]
  renderObject: RenderView#16531
The offending element (which does not appear to be a descendant of the root of the build scope) was: FocusScope
  debugLabel: "_ModalScopeState<dynamic> Focus Scope"
  focusNode: FocusScopeNode#c6bfe(_ModalScopeState<dynamic> Focus Scope [PRIMARY FOCUS])
  dirty
  dependencies: [_FocusMarker]
  state: _FocusScopeState#e871c
When the exception was thrown, this was the stack: 
#0      BuildOwner.buildScope.<anonymous closure> (package:flutter/src/widgets/framework.dart:2675:13)
#1      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2700:10)
#2      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:882:21)
#3      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:367:5)
#4      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1145:15)
#5      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1082:9)
#6      SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#10     _invoke (dart:ui/hooks.dart:151:10)
#11     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
#12     _drawFrame (dart:ui/hooks.dart:115:31)
(elided 3 frames from dart:async)
====================================================================================================
W/IInputConnectionWrapper( 4436): setComposingText on inactive InputConnection
W/IInputConnectionWrapper( 4436): getTextBeforeCursor on inactive InputConnection

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: solvedIssue is closed as solved

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions