Created
December 21, 2022 20:04
-
-
Save webmstk/faabc653098e1995bd45c2980a5aa07e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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