getChildrenAsList method Null safety

List<ChildType> getChildrenAsList()

Returns a list containing the children of this render object.

This function is useful when you need random-access to the children of this render object. If you're accessing the children in order, consider walking the child list directly.

Implementation

List<ChildType> getChildrenAsList() {
  final List<ChildType> result = <ChildType>[];
  RenderBox? child = firstChild;
  while (child != null) {
    final ParentDataType childParentData = child.parentData! as ParentDataType;
    result.add(child as ChildType);
    child = childParentData.nextSibling;
  }
  return result;
}