snapshotChildPresence method
Every live node's key, mapped to whether it currently has live children.
The cheap counterpart to snapshotCurrentChildren, for callers that only ask "which nodes exist" and "does this one have children". Those are the only two questions the initial-expansion and auto-expand passes ask, and answering them through snapshotCurrentChildren would copy every child key in the tree once per call, twice per sync, to produce lists nothing reads.
The key set is identical to snapshotCurrentChildren's: one entry per live node, leaves included and mapped to false. Exiting (pending-deletion) nodes are excluded from the key set and are not counted as children, matching that method.
Iterates the controller's child lists through the unmodifiable view rather than the live-filtered copies, so the walk allocates the result map and nothing per node.
Implementation
Map<TKey, bool> snapshotChildPresence() {
final out = <TKey, bool>{};
// Iterative DFS so deep linear chains do not overflow the Dart stack.
final stack = <TKey>[];
for (final rootKey in _controller.rootKeys) {
if (!_controller.isPendingDeletion(rootKey)) {
stack.add(rootKey);
}
}
while (stack.isNotEmpty) {
final key = stack.removeLast();
var hasLiveChildren = false;
for (final childKey in _controller.getChildren(key)) {
if (_controller.isPendingDeletion(childKey)) {
continue;
}
hasLiveChildren = true;
stack.add(childKey);
}
out[key] = hasLiveChildren;
}
return out;
}