writeRecord method

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

Implementation

void writeRecord(
  int indent,
  Map<String, dynamic> map, {
  /// If `recursive` is `true`, a `Map` will be converted into a `Record`, and
  /// its `Map` values will be converted as well. Otherwise, they will be written
  /// as a literal `Map`.
  bool recursive = true,

  /// 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) {
    buffer.write('${_generateIndent(indent)}${safeName(entry.key)}: ');
    if (entry.value is List) {
      writeList(
        indent + 2,
        entry.value,
        stringAsAny: stringAsAny,
      );
    } else if (entry.value is Map) {
      if (recursive) {
        writeRecord(
          indent + 2,
          entry.value,
          stringAsAny: stringAsAny,
        );
      } else {
        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)})');
}