mapToString method

String mapToString({
  1. int indentation = 2,
})

Implementation

String mapToString({int indentation = 2}) {
  String result = "";
  String indentationStr = " " * indentation;

  result += "{";
  forEach((key, value) {
    if (value is Map) {
      var temp = value.mapToString(indentation: indentation + 2);
      result += "\n$indentationStr" "\"$key\" : $temp,";
    } else if (value is List) {
      result += "\n$indentationStr"
          "\"$key\" : ${value.listToString(indentation: indentation + 2)},";
    } else {
      result += "\n$indentationStr" "\"$key\" : \"$value\",";
    }
  });
  result = result.substring(0, result.length - 1);
  result += indentation == 2 ? "\n}" : "\n${" " * (indentation - 1)}}";
  return result;
}