removeChildren method

  1. @override
void removeChildren([
  1. int beginIndex = 0,
  2. int? endIndex
])
override

Removes all child DisplayObject instances from the child list of this DisplayObjectContainer instance.

Optionally, an index range may be specified with beginIndex and endIndex.

The parent property of the removed children is set to null, and the objects are garbage collected if no other references to the children exist.

Implementation

@override
void removeChildren([int beginIndex = 0, int? endIndex]) {
  final length = _children.length;
  final i1 = beginIndex;
  final i2 = endIndex ?? length - 1;
  if (i1 > i2) {
    // do nothing
  } else if (i1 < 0 || i1 >= length || i2 < 0 || i2 >= length) {
    throw ArgumentError('The supplied index is out of bounds.');
  } else {
    for (var i = i1; i <= i2 && i1 < _children.length; i++) {
      removeChildAt(i1);
    }
  }
}