Skip to content

Null pointer in Overlay when visiting ancestors #37161

@matthew-carroll

Description

@matthew-carroll

I was poking around BuildContext APIs and tried to invoke visitAncestorElements() all the way up the tree. I invoked visitAncestorElements() from my widget's build() method. I ran into a null pointer error for _offstage in Overlay at:

for (Element child in _offstage) {

The error was:

flutter: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following NoSuchMethodError was thrown building MyDescendant6(dirty):
flutter: The getter 'iterator' was called on null.
flutter: Receiver: null
flutter: Tried calling: iterator
flutter:
flutter: User-created ancestor of the error-causing widget was:
flutter:   Padding
flutter:   file:///Users/[redacted]/buildcontext_ancestors.dart:177:18
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
flutter: #1      _TheatreElement.visitChildren (package:flutter/src/widgets/overlay.dart:566:27)
...

It's possible that this error was the result of me mis-using the API, but in that case the API docs should probably be updated with the limitation, and maybe an appropriate error should be thrown when this happens.

Flutter Doctor:

 • Flutter version 1.8.2-pre.216 at [redacted]
    • Framework revision 24f483cf25 (5 hours ago), 2019-07-28 21:44:21 -0700
    • Engine revision 38ac5f30a7
    • Dart version 2.5.0 (build 2.5.0-dev.1.0 0ca1582afd)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: contributor-productivityTeam-specific productivity, code health, technical debt.frameworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions