I have a desktop app, with a layout like:
TitleBar()
========================
IndexedStack(children: [Page1(), Page2()])
When on Page 1 (for example) I want the focus traversal to go from the TitleBar > Page1 > TitleBar, but what it does instead is TitleBar > Page1 > Page2 > TitleBar.
Wrapping each child in a FocusScope
doesn't work, since I want TitleBar to be able to go into Page1. Wrapping in Focus and setting canRequestFocus
does not work. Using multiple TraversalGroups does not work.
Any idea? I need the equivalent of IgnorePointer()
for focus events. Then I could have:
TitleBar(),
IndexedStack(
children: [
BlockFocus(block: index != 0, child: Page1()),
BlockFocus(block: index != 1, child: Page2()),
]
)
I've tried using TraversalGroup + descendantsAreFocusable=false, but good old Flutter screams at me with an assertion, even tho this is exactly what I want to do:
sorted descendants contains more nodes than it should: ({FocusNode#9a2ed(FocusTraversalGroup)(context: Focus, NOT FOCUSABLE)})
Failed assertion: line 340 pos 7: 'sortedDescendants.length <= scope.traversalDescendants.length && sortedDescendants.toSet().difference(scope.traversalDescendants.toSet()).isEmpty'
The docs on this property are not helpful:
/// {@macro flutter.widgets.Focus.descendantsAreFocusable}
final bool descendantsAreFocusable;
I've also tried:
FocusScope(skipTraversal: true, child: child)
And it does nothing, still allowing all the nodes to be focused. Getting kinda frustrating that nothing just acts like it should :/ descendantsAreFocusable
throws an error for no apparent reason, skipTraversal
does not actually skip traversal.
question from:
https://stackoverflow.com/questions/65888930/flutter-how-to-disable-focustraversal-for-non-visible-children 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…