我在这里找到了能够从控制台读取的答案:Is it possible to read from console in Dart? . 但是,我想阻止程序中的进一步执行,直到输入字符串(想想只是与用户进行简单的控制台交互)。
但是,我没有看到一种方法来控制简单交互的执行流程。我意识到 Dart I/O 是异步的,所以我正在努力弄清楚我应该如何完成这个看似简单的任务。只是我试图将 Dart 用于它不打算做的事情吗?
#import("dart:io");
void main() {
var yourName;
var yourAge;
var console = new StringInputStream(stdin);
print("Please enter your name? ");
console.onLine = () {
yourName = console.readLine();
print("Hello $yourName");
};
// obviously the rest of this doesn't work...
print("Please enter your age? ");
console.onLine = () {
yourAge = console.readLine();
print("You are $yourAge years old");
};
print("Hello $yourName, you are $yourAge years old today!");
}