removeChildren method
Implementation
void removeChildren(DomRenderObject parent) {
assert(parent == this.parent, 'Cannot remove fragment from a different parent.');
assert(isAttached, 'Cannot remove fragment that is not attached to a parent.');
if (kVerboseMode) {
print("Remove fragment $node from ${parent.node}");
}
if (firstChildNode == null) {
// If fragment is empty, nothing to remove.
return;
}
assert(lastChildNode != null, 'Non-empty attached fragments must have a valid last child reference.');
web.Node? currentNode = lastChildNode;
web.Node? beforeNode;
while (currentNode != null) {
final prevNode = currentNode != firstChildNode ? currentNode.previousSibling : null;
assert(currentNode.parentNode == parent.node, 'Fragment child must be a child of the parent.');
// Remove from parent, attach back to fragment.
node.insertBefore(currentNode, beforeNode);
beforeNode = currentNode;
currentNode = prevNode;
}
assert(firstChildNode == node.childNodes.item(0), 'First child node should be the first child of the fragment.');
assert(
lastChildNode == node.childNodes.item(node.childNodes.length - 1),
'Last child node should be the last child of the fragment.',
);
isAttached = false;
}