addChildAt method Null safety

  1. @override
void addChildAt(
  1. DisplayObject child,
  2. int index

Adds a child DisplayObject to this DisplayObjectContainer at the specified index position.

An index of 0 represents the back (bottom) of the display list for this DisplayObjectContainer.

If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.


void addChildAt(DisplayObject child, int index) {
  if (index < 0 || index > _children.length) {
    throw ArgumentError('The supplied index is out of bounds.');
  } else if (child == this) {
    throw ArgumentError('An object cannot be added as a child of itself.');
  } else if (child.parent == this) {
    _addLocalChildAt(child, index);
  } else {
    _children.insert(index, child);