Skip to content

Assert triggered in focus_manager #136758

Description

@saintmac-google

Steps to reproduce

Got hit by this assert:
https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/focus_manager.dart#L1268

We have in our app a FocusScope with children nodes and subnodes.
When I press ESC, the tree underneath the FocusScope is being removed, however the FocusScope in _focusedChildren still lists out indirect children that have been removed.

it looks like we're not updating the _focusedChildren of descendants when removing a child from its parent

https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/focus_manager.dart#L967

I fixed it with this piece of code in _removeChild:

   if (removeScopeFocus) {
      final enclosingScope = node.enclosingScope;
      if (enclosingScope != null) {
        enclosingScope?._focusedChildren.remove(node);
        for (final descendant in node.descendants) {
          if (descendant.enclosingScope == enclosingScope)
            enclosingScope?._focusedChildren.remove(descendant);
        }
      }
    }

Expected results

no assert

Actual results

assert triggered

Activity

  1. self-assigned this
    on Oct 17, 2023
  2. github-actions commented on Nov 2, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  3. locked as resolved and limited conversation to collaborators on Nov 2, 2023
  4. added
    fyi-macosFor the attention of macOS platform team
    fyi-windowsFor the attention of the Windows platform team
    fyi-linuxFor the attention of the Linux platform team
    and removed on Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listf: focusFocus traversal, gaining or losing focusfyi-linuxFor the attention of the Linux platform teamfyi-macosFor the attention of macOS platform teamfyi-windowsFor the attention of the Windows platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions