How to read console input on M3 Dart

后端 未结 1 803
半阙折子戏
半阙折子戏 2020-12-20 20:30

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

1条回答
  •  时光说笑
    2020-12-20 21:09

    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. */);
    
    
    }
    

    0 讨论(0)
提交回复
热议问题