writeMap method

void writeMap(
  1. int indent,
  2. Map<String, dynamic> map, {
  3. bool stringAsAny = false,
})

Implementation

void writeMap(
  int indent,
  Map<String, dynamic> map, {
  /// If `true`, `String` will be treated as a generic value, thus no quote characters
  /// will be written.
  bool stringAsAny = false,
}) {
  buffer.write('{\n');
  for (final entry in map.entries) {
    if (entry.key.contains("'")) {
      buffer.write(
        '${_generateIndent(indent)}"${entry.key}": ',
      );
    } else {
      buffer.write(
        "${_generateIndent(indent)}'${entry.key}': ",
      );
    }
    if (entry.value is List) {
      writeList(
        indent + 2,
        entry.value,
        stringAsAny: stringAsAny,
      );
    } else if (entry.value is Map) {
      writeMap(
        indent + 2,
        entry.value,
        stringAsAny: stringAsAny,
      );
    } else if (stringAsAny) {
      writeAny(0, entry.value);
    } else {
      if (entry.value is String) {
        writeString(0, entry.value);
      } else {
        writeAny(0, entry.value);
      }
    }
    buffer.write(',\n');
  }
  buffer.write('${_generateIndent(indent - 2)}}');
}