mapToStructureString method

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

Implementation

String mapToStructureString({int indentation = 0, String space = "  "}) {
  if (this == null || this.isEmpty) {
    return "$this";
  }
  String result = "";
  String indentationContent = space * indentation;
  result += "{";
  this.forEach((key, value) {
    if (value is Map) {
      result += "\n$indentationContent" +
          "\"$key\": ${value.mapToStructureString(indentation: indentation + 1)},";
    } else if (value is List) {
      result += "\n$indentationContent" +
          "\"$key\": ${value.listToStructureString(indentation: indentation + 1)},";
    } else {
      result += "\n$indentationContent" +
          "\"$key\": ${value is String ? "\"$value\"," : "$value,"}";
    }
  });
  result = result.substring(0, result.length - 1);
  result += "\n$indentationContent}";
  return result;
}