attachChild method
Implementation
void attachChild(DomRenderObject child, DomRenderObject? after, {web.Node? startNode}) {
child.parent = this;
final targetNode = attachTargetNode;
final afterNode = getRealNodeOf(after) ?? startNode;
if (child case DomRenderFragment(isAttached: true)) {
child.move(this, targetNode, afterNode);
return;
}
try {
final childNode = child.node;
if (childNode.previousSibling == afterNode && childNode.parentNode == targetNode) {
return;
}
if (kVerboseMode) {
print("Attach node $childNode to $targetNode after $afterNode ($after)");
}
if (afterNode == null) {
targetNode.insertBefore(childNode, targetNode.childNodes.item(0));
} else {
targetNode.insertBefore(childNode, afterNode.nextSibling);
}
if (child is! DomRenderFragment) {
assert(childNode.previousSibling == afterNode, 'Child node should have been placed after the specified node.');
} else if (child.firstChildNode != null) {
assert(
child.firstChildNode?.previousSibling == afterNode,
'Fragment first child should have been placed after the specified node.',
);
}
final next = after?.nextSibling;
child.previousSibling = after;
after?.nextSibling = child;
child.nextSibling = next;
next?.previousSibling = child;
} finally {
child.finalize();
}
}