joan
joan

Reputation: 2531

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?

Upvotes: 6

Views: 672

Answers (1)

joan
joan

Reputation: 2531

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


}

Upvotes: 4

Related Questions