debugDescribeChildren method Null safety

  1. @override
List<DiagnosticsNode> debugDescribeChildren()
override

Returns a list of DiagnosticsNode objects describing this node's children.

Children that are offstage should be added with style set to DiagnosticsTreeStyle.offstage to indicate that they are offstage.

The list must not contain any null entries. If there are explicit null children to report, consider DiagnosticsNode.message or DiagnosticsProperty<Object> as possible DiagnosticsNode objects to provide.

Used by toStringDeep, toDiagnosticsNode and toStringShallow.

See also:

Implementation

@override
List<DiagnosticsNode> debugDescribeChildren() {
  final List<DiagnosticsNode> children = <DiagnosticsNode>[];
  if (firstChild != null) {
    ChildType child = firstChild!;
    int count = 1;
    while (true) {
      children.add(child.toDiagnosticsNode(name: 'child $count'));
      if (child == lastChild) {
        break;
      }
      count += 1;
      final ParentDataType childParentData = child.parentData! as ParentDataType;
      child = childParentData.nextSibling!;
    }
  }
  return children;
}