How to read console input on M3 Dart

2019-01-28 00:10发布

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

1条回答
ゆ 、 Hurt°
2楼-- · 2019-01-28 00:47

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


}
查看更多
登录 后发表回答