requestFocus method
void
requestFocus()
Requests focus for this node, unfocusing other sibling branches recursively.
Implementation
void requestFocus() {
// 1. Find root
var root = this;
while (root.parent != null) {
root = root.parent!;
}
// 2. Unfocus everything under root
root._unfocusRecursive();
// 3. Focus path from this node to root
FocusNode? current = this;
while (current != null) {
final wasFocused = current.isFocused;
current.isFocused = true;
if (!wasFocused) {
current.onFocusChange?.call(true);
}
if (current is FocusScopeNode) {
FocusNode? childOnPath;
for (final child in current.children) {
if (child.isFocused) {
childOnPath = child;
break;
}
}
if (childOnPath != null) {
current._focusedChild = childOnPath;
}
}
current = current.parent;
}
}