Splits a multiline string into a list of lines.

Use String.split() and a regular expression to match line breaks and create a list.

代码实现

List<String> splitLines(String str) {
  return str.split(RegExp(r'\r?\n'));
}

使用样例

splitLines('This\nis a\nmultiline\nstring.\n'); // ['This', 'is a', 'multiline', 'string.' , '']