listToStructureString method

String listToStructureString({
  1. int indentation = 0,
  2. String space = " ",
})

Implementation

String listToStructureString({int indentation = 0, String space = "  "}) {
  if (this == null || this.isEmpty) {
    return "$this";
  }
  String result = "";
  String indentationContent = space * indentation;
  result += "[";
  for (var value in this) {
    if (value is Map) {
      result += "\n$indentationContent" +
          space +
          "${value.mapToStructureString(indentation: indentation + 1)},"; // 加空格更好看
    } else if (value is List) {
      result += value.listToStructureString(indentation: indentation + 1);
    } else {
      result += "\n$indentationContent" + value is String
          ? "\"$value\","
          : "$value,";
    }
  }
  result = result.substring(0, result.length - 1);
  result += "\n$indentationContent]";
  return result;
}