hangingIndent method
Adds indentation to all lines except the first (hanging indent).
Common in typography for bullet lists, quoted text, or wrapped paragraphs where the first line starts at the margin and subsequent lines are indented.
Example:
'line1\nline2\nline3'.hangingIndent(' ')
// 'line1\n line2\n line3'
'This is a very long line that wraps.\nContinuation line.'.hangingIndent(' ')
// 'This is a very long line that wraps.\n Continuation line.'
Implementation
String hangingIndent(String indentation) {
if (isEmpty) return this;
final lines = split('\n');
if (lines.length == 1) return this;
return [lines.first, ...lines.skip(1).map((line) => indentation + line)].join('\n');
}