停止执行Dart程序,直到按下某个键

obo*_*ain 4 dart

有没有办法在按下某个键之前停止执行Dart进程?

这将是这样的:

  • 在html文件中:
<input id="nextstep" type="button" value="nextstep" />
Run Code Online (Sandbox Code Playgroud)
  • 在dart文件中:
void main() { 
  while(true) {
    // Do something here to pause the loop 
    // until the nextstep button is pressed
  } 
}
Run Code Online (Sandbox Code Playgroud)

Ale*_*uin 6

您只需添加一个keyPress监听器input即可开始一些额外的处理.

void main() { 
  final input = querySelector("#nextstep");
  input.onKeyPress.listen((e){
    nextProcessingStep();
  });
} 
Run Code Online (Sandbox Code Playgroud)