Skip to content

Instantly share code, notes, and snippets.

@webmstk
Created December 21, 2022 20:04
Show Gist options
  • Save webmstk/faabc653098e1995bd45c2980a5aa07e to your computer and use it in GitHub Desktop.
Save webmstk/faabc653098e1995bd45c2980a5aa07e to your computer and use it in GitHub Desktop.
import 'dart:io';
Future<void> main() async {
// 1.
print('Что говорит собачка?');
var value = await userInput();
print('Введена строка $value');
print('\nЧто говорит кошка?');
userInput().then((value) => print('Введена строка $value'));
// 2.
userInputStream().listen((input) {
print('Введена строка $input');
});
}
// 1.
Future<String> userInput() {
return Future.value(stdin.readLineSync());
}
// 2.
Stream userInputStream() async* {
String? input;
do {
input = stdin.readLineSync();
yield input;
} while (input != 'exit');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment