ここでコンソールから読み取ることができることに対する答えを見つけました: 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!");
}