Is it possible to read from console in Dart?

console, dart

Solution

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;

Problem

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

Original source

Related problems