addChildAt<T extends GDisplayObject> method
Adds a child to the list of children of this container at a specific index.
The type parameter T
specifies the type of the child to add.
Implementation
T addChildAt<T extends GDisplayObject>(T child, int index) {
if (index < 0 || index > children.length) {
throw RangeError('Invalid child index');
}
requiresRedraw();
if (child.$parent == this) {
setChildIndex(child, index);
} else {
children.insert(index, child);
child.removeFromParent();
child.$setParent(this);
child.$onAdded?.dispatch();
if (stage != null) {
child.$onAddedToStage?.dispatch();
if (child is GDisplayObjectContainer) {
_broadcastChildrenAddedToStage(child);
}
child.addedToStage();
}
}
return child;
// child?.parent?.removeChild(child);
// child.parent = this;
// children.insert(index, child);
// child.$stage = stage;
// if (child is DisplayObjectContainer) {}
}