splitLines method

List<String> splitLines()

Splits the String into a List of lines ('\r\n' or '\n').

If the String is null, an ArgumentError is thrown.

Example

String text = 'hello\nworld';
List<String> lines = text.splitLines();
print(lines); // prints ['hello', 'world']

Implementation

List<String> splitLines() {
  if (this == null) {
    throw ArgumentError('String is null');
  }
  return this!.split(RegExp(r'\r?\n'));
}