Similar to this question (java), how can I get the platform-dependent line separator in Flutter?
I tried the Platform
class but it doesn't seem to have it.
If there is no "dart-built-in way" of doing it, you can use an extension, something like:
import 'dart:io';
extension PlatformExtension on Platform {
String get lineSeparator => Platform.isWindows
? '\r\n'
: Platform.isMacOS
? '\r'
: Platform.isLinux
? '\n'
: '\n';
}
Then it can be used as:
String s = Platform().lineSeparator;
As jamesdlin suggested in the comment, LineSplitter
can also come in handy when reading from text files.