Dumping Mapping topic
Dumps any Map-like objects.
Flow Mappings
Flow mappings start with { and terminate with }. All entries are always dumped on a new line. The default scalar style for flow mappings is ScalarStyle.doubleQuoted.
Implicit keys
Inline keys are dumped as implicit keys.
dumpMapping(
{ 'key': 'value' },
collectionNodeStyle: NodeStyle.flow,
);
# Output in yaml
{
"key": "value"
}
Explicit keys
Collections or multiline scalars are encoded with an explicit key.
dumpMapping(
{ {'key': 'value'} : {'key': 'value'} },
collectionNodeStyle: NodeStyle.flow,
);
# Output in yaml
{
? {
"key": "value"
}: {
"key": "value"
}
}
Block Mappings
Block mapping have no explicit starting or terminating indicators. The default scalar style for block mappings is ScalarStyle.literal.
Explicit keys
Block mappings have a low threshold for explicit keys. Keys are encoded as explicit keys if:
- The
keyScalarStyleis a block scalar style (literalorfolded) or isnull. - The scalar is spans multiple line.
- The key is a collection (
MaporIterable).
dumpMapping(
{ 'key': 'value' },
collectionNodeStyle: NodeStyle.block,
keyScalarStyle: ScalarStyle.literal,
valueScalarStyle: ScalarStyle.plain
);
# Output in yaml
? |-
key
: value
Implicit keys
Only inline flow scalars are dumped as implicit keys.
dumpMapping(
{ 'key': 'value' },
collectionNodeStyle: NodeStyle.block,
keyScalarStyle: ScalarStyle.plain,
valueScalarStyle: ScalarStyle.singleQuoted,
);
# Output in yaml
key: 'value'
Functions
-
dumpMapping<
M extends Map> (M mapping, {int indent = 0, bool jsonCompatible = false, NodeStyle? collectionNodeStyle, ScalarStyle? keyScalarStyle, ScalarStyle? valueScalarStyle}) → String Dumping Mapping -
Dumps a
mappingwhich must be a Mapping orDartMap.