encodeYaml function
Encodes data as a YAML string, using two-space indentation and block
style throughout (mappings and sequences are never written in flow
style, even though decodeYaml can read flow style).
data must be composed of Map<String, dynamic> (or any Map),
List<dynamic>, String, num, bool, and null.
Implementation
String encodeYaml(dynamic data) {
final buf = StringBuffer();
if (data is Map && data.isNotEmpty) {
_writeYamlMap(buf, data, 0);
} else if (data is List && data.isNotEmpty) {
_writeYamlList(buf, data, 0);
} else if (data is Map) {
buf.writeln('{}');
} else if (data is List) {
buf.writeln('[]');
} else {
buf.writeln(_formatYamlScalar(data));
}
return buf.toString();
}