formatMap method

String formatMap()

Formats this map as a human-readable string with indentation.

Implementation

String formatMap() {
  if (isEmpty) return '';
  const String indent = '  ';
  final StringBuffer buffer = StringBuffer('{\n');
  forEach((String mapKey, dynamic mapValue) {
    buffer.write(indent);
    buffer.write(mapKey);
    buffer.write(': ');
    if (mapValue is Map<String, dynamic>) {
      buffer.write(mapValue.formatMap());
      buffer.write('\n');
    } else if (mapValue is List) {
      buffer.write('[\n');
      for (dynamic listItem in mapValue) {
        buffer.write(indent);
        buffer.write(indent);
        buffer.write(listItem);
        buffer.write(',\n');
      }
      buffer.write(indent);
      buffer.write('],\n');
    } else {
      buffer.write(mapValue);
      buffer.write(',\n');
    }
  });
  buffer.write('}');
  return buffer.toString();
}