Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read console input on M3 Dart

With M3 the classes like StringInputStream are replaced with Stream. How can I read stdin input on a server application?

like image 861
joan Avatar asked Mar 15 '13 18:03

joan


1 Answers

Try this:

import 'dart:io';
import 'dart:async';

void main() {
  print("Please, enter a line \n");
  Stream cmdLine = stdin
      .transform(new StringDecoder())
      .transform(new LineTransformer());

  StreamSubscription cmdSubscription = cmdLine.listen(
    (line) => print('Entered line: $line '),
    onDone: () => print(' finished'),
    onError: (e) => /* Error on input. */);


}
like image 174
joan Avatar answered Oct 20 '22 15:10

joan