toFormattedString method

  1. @override
String toFormattedString(
  1. {int nestingLevel = 0,
  2. String indent = '\t',
  3. bool encodeCharacterEntities = true,
  4. String? encodeCharacters,
  5. bool doubleQuotes = true}
)
override

Returns this node as a formatted string.

Each child is returned further indented by indent with each nestingLevel.

If lineLength isn't null, lines will be broken when they reach lineLength in length. Some lines may not be broken by lineLength if a clean way to break them can't be detected.

nestingLevel must not be null and must be >= 0.

indent defaults to \t (tab) and must not be null.

lineLength must not be null and must be > 0.

Implementation

@override
String toFormattedString({
  int nestingLevel = 0,
  String indent = '\t',
  bool encodeCharacterEntities = true,
  String? encodeCharacters,
  bool doubleQuotes = true,
}) {
  assert(nestingLevel >= 0);

  final tag = _buildTag(
    doubleQuotes: doubleQuotes,
    encodeCharacterEntities: encodeCharacterEntities,
    encodeCharacters: encodeCharacters,
  );

  var element = tag.formatLine(nestingLevel, indent);

  if (children != null) {
    element += children!.format(
      nestingLevel: nestingLevel,
      indent: indent,
      encodeCharacterEntities: encodeCharacterEntities,
      encodeCharacters: encodeCharacters,
      doubleQuotes: doubleQuotes,
    );

    element += '</$name>'.formatLine(nestingLevel, indent);
  }

  return element;
}