syncMultipleChildren method
void
syncMultipleChildren(})
Syncs children for multiple parents in a single batch.
This is the safe way to reparent nodes across parents when calling syncChildren directly (outside of syncRoots). The method pre-computes the union of all desired child keys so that removal of a node from its old parent is deferred when it is desired under a different parent, allowing TreeController.moveNode to preserve subtree state.
Set animate to false to suppress animations.
Implementation
void syncMultipleChildren(
Map<TKey, List<TreeNode<TKey, TData>>> desiredByParent, {
bool animate = true,
}) {
_controller.runBatch(() {
_globallyDesiredChildren = <TKey>{};
try {
for (final children in desiredByParent.values) {
for (final c in children) {
_globallyDesiredChildren!.add(c.key);
}
}
for (final entry in desiredByParent.entries) {
syncChildren(entry.key, entry.value, animate: animate);
}
} finally {
_globallyDesiredChildren = null;
}
});
}