Skip to content

Assert triggered in focus_manager #136758

@saintmac-google

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

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