toJsonList method Null safety

List<Map<String, Object?>> toJsonList(
  1. List<DiagnosticsNode>? nodes,
  2. DiagnosticsNode? parent,
  3. DiagnosticsSerializationDelegate delegate
)

Serializes a List of DiagnosticsNodes to a JSON list according to the configuration provided by the DiagnosticsSerializationDelegate.

The provided nodes may be properties or children of the parent DiagnosticsNode.

Implementation

static List<Map<String, Object?>> toJsonList(
  List<DiagnosticsNode>? nodes,
  DiagnosticsNode? parent,
  DiagnosticsSerializationDelegate delegate,
) {
  bool truncated = false;
  if (nodes == null) {
    return const <Map<String, Object?>>[];
  }
  final int originalNodeCount = nodes.length;
  nodes = delegate.truncateNodesList(nodes, parent);
  if (nodes.length != originalNodeCount) {
    nodes.add(DiagnosticsNode.message('...'));
    truncated = true;
  }
  final List<Map<String, Object?>> json = nodes.map<Map<String, Object?>>((DiagnosticsNode node) {
    return node.toJsonMap(delegate.delegateForNode(node));
  }).toList();
  if (truncated) {
    json.last['truncated'] = true;
  }
  return json;
}