How to read console input on M3 Dart

青春壹個敷衍的年華 提交于 2019-12-18 08:08:21

问题


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


回答1:


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


}


来源:https://stackoverflow.com/questions/15440138/how-to-read-console-input-on-m3-dart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!