Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PopoverItem._configureRect() throws trying to access unmounted context when popover is open #63

Closed
moescs opened this issue Feb 28, 2023 · 1 comment · Fixed by #64
Closed
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@moescs
Copy link
Contributor

moescs commented Feb 28, 2023

Describe the bug
If you enable widget selection mode in VSCode's Widget Inspector while the popover is open, it triggers didChangeDependencies to schedule a _configureRect in PopoverItem. The problem is that the BuildContext becomes unmounted between didChangeDependencies and the post frame callback.

To Reproduce
Steps to reproduce the behavior:

  1. Use VSCode.

  2. Add a popover using showPopover().

  3. Run the app using VSCode's debugger.

  4. Open the Widget Inspector.

  5. Open the popover in the app (trigger a call to showPopover()).

  6. Click the toggle button to turn select widget mode on in the Widget Inspector.

  7. BuildContextExtension.getWidgetLocalToGlobal() in _configureRect() throws the following error:

    FlutterError (Cannot get renderObject of inactive element.
    In order for an element to have a valid renderObject, it must be active, which means it is part of the tree.
    Instead, this element is in the _ElementLifecycle.defunct state.
    If you called this method from a State object, consider guarding it with State.mounted.
    The findRenderObject() method was called for the following element:
    StatelessElement#7e777(DEFUNCT))

Expected behavior
No error should be thrown.

Desktop (please complete the following information):

  • OS: Windows 11
  • Desktop app
  • Version 10.0.22621 Build 22621

Additional comments
A possible solution is to add if (!widget.context.mounted) return; at the top of _configureRect(). I would generate a pull request, but I'm not sure if this would be exempt from testing when reading your guidelines. I can't think of a good way to test it.

@minikin
Copy link
Owner

minikin commented Feb 28, 2023

@moescs Thank you for the report. I don't have access to a Windows machine.
Would you mind creating a PR with the fix and recording a short video to showcase that the issue is fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
2 participants