debugDescribeChildren method Null safety

  1. @override
List<DiagnosticsNode> debugDescribeChildren()

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:


List<DiagnosticsNode> debugDescribeChildren() {
  if (children == null) {
    return const <DiagnosticsNode>[];
  return children!.map<DiagnosticsNode>((InlineSpan child) {
    // `child` has a non-nullable return type, but might be null when running
    // with weak checking, so we need to null check it anyway (and ignore the
    // warning that the null-handling logic is dead code).
    if (child != null) {
      return child.toDiagnosticsNode();
    } else {
      return DiagnosticsNode.message('<null child>');