snapshotCurrentChildren method
Returns a deep-copied snapshot of the current live child order, derived from the controller.
The returned map and lists are detached from the controller's internal state, so callers can safely compare snapshots across sync operations. Exiting (pending-deletion) nodes are excluded: they are on their way out and not part of the current logical tree.
Implementation
Map<TKey, List<TKey>> snapshotCurrentChildren() {
final out = <TKey, List<TKey>>{};
// Iterative DFS so deep linear chains do not overflow the Dart stack.
final stack = <TKey>[..._controller.liveRootKeys];
while (stack.isNotEmpty) {
final key = stack.removeLast();
final children = _controller.getLiveChildren(key);
out[key] = children;
for (final childKey in children) {
stack.add(childKey);
}
}
return out;
}