I know that we can print to the console in dart using the print() statement.
I want to know if it is possible to read data from console. I did a search and also looked in the dart:io package, but couldn't find any reference.
Thanks
Stdout represents the IOSink for either stdout or stderr . It provides a blocking IOSink , so using this to write will block until the output is written. In some situations this blocking behavior is undesirable as it does not provide the same non-blocking behavior as dart:io in general exposes.
Dart – Print without Newline To print a string to console without a trailing new line in Dart, import dart:io library, and call stdout. write() function with the string passed as argument to it.
You can use StringInputStream to read from stdin like this
#import("dart:io");
main() {
var stream = new StringInputStream(stdin);
stream.onLine = () {
var line = stream.readLine();
if (line != null) {
print(line);
}
};
}
also if you're developing a console application then checkout the Options class to parse command line arguments
final args = new Options().arguments;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With