lines property
The text that ended up on each line after line breaking.
Hard line breaks are not included in the returned strings.
Implementation
List<String> get lines {
final text = plainText;
final out = <String>[];
var offset = 0;
while (offset < text.length) {
var range = _textPainter.getLineBoundary(TextPosition(offset: offset));
// Flutter web sometimes reports the range of the previous line instead
// of the one containing the offset, see
// https://github.com/flutter/flutter/issues/188874
if (range.start < offset) {
range = _textPainter.getLineBoundary(TextPosition(offset: offset + 1));
}
final end = max(range.end, offset + 1);
var line = text.substring(offset, end);
if (line.endsWith('\n')) {
line = line.substring(0, line.length - 1);
}
out.add(line);
offset = end;
if (offset < text.length && text[offset] == '\n') {
offset++;
}
}
return out;
}