Skip to content

crash on nested Navigator with GlobalKey #26704

@SteveAlexander

Description

@SteveAlexander

The following flutter project reproduces the issue. Run the project, press button "1", then press button "2".

https://github.com/SteveAlexander/navigator_issue

When using two levels of nested Navigator, where they have GlobalKeys, on the second route pushed, the app crashes with the following error:

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building FocusScope(dirty, state: _FocusScopeState#7e10a):
flutter: 'package:flutter/src/widgets/focus_manager.dart': Failed assertion: line 315 pos 12: 'child._parent
flutter: == null || child._parent == this': is not true.
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
flutter:   https://github.com/flutter/flutter/issues/new?template=BUG.md
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2      FocusScopeNode.setFirstFocus (package:flutter/src/widgets/focus_manager.dart:315:12)
flutter: #3      FocusScopeNode.reparentScopeIfNeeded (package:flutter/src/widgets/focus_manager.dart:338:7)
flutter: #4      _FocusScopeState.build (package:flutter/src/widgets/focus_scope.dart:104:28)
flutter: #5      StatefulElement.build (package:flutter/src/widgets/framework.dart:3809:27)
flutter: #6      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3721:15)
flutter: #7      Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #8      StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
flutter: #9      Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #10     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #11     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #12     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
flutter: #13     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #14     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #15     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #16     StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
flutter: #17     Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
flutter: #18     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2943:38)
flutter: #19     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #20     SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
flutter: #21     Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
flutter: #22     Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
flutter: #23     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
flutter: #24     Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
flutter: #25     ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
flutter: #26     ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
etc.

The exception looks similar to #11719, but while that one is about TextFields, this one is specific to how Navigators interact with GlobalKeys.

The problem also looks similar to this old issue about nested focus scopes, fixed by @Hixie in 2015: #448

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: crashStack traces logged to the consolef: routesNavigator, Router, and related APIs.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions