indentLines method

  1. @useResult
String indentLines(
  1. String prefix
)

Prepends prefix to every line (after splitting by newline).

Line breaks are normalized to \n before splitting. prefix must not be null. Returns a new string with each line prefixed.

Example:

'a\nb'.indentLines('  ');  // '  a\n  b'

Implementation

@useResult
String indentLines(String prefix) {
  if (isEmpty) return this;
  final List<String> lines = split('\n');
  return lines.map((String line) => prefix + line).join('\n');
}