How to listen for a keyboard event when programming a dart

I am new to google dart and trying to learn this for a day. I am new to programming in general and am trying to read the documentation; however, I feel a little overwhelmed.

I would like to know the most correct way to create interaction for the here key . When you press the spacebar, it will switch between void startwatch (), void resetwatch () function

I believe this is the correct documentation page and documentation for keyboardEventController

void main() {

}

void startwatch() {
  mywatch.start();
  var oneSecond = new Duration(milliseconds:1);
  var timer = new Timer.repeating(oneSecond, updateTime);
}

void resetwatch() {
  mywatch.reset();
  counter = '00:00:00';
}

Any additional information is required. I will try to answer immediately. Thnk you so much for your help.

+5
source share
1 answer

startwatch() resetwatch():

void main() {
  var started = false;

  window.onKeyUp.listen((KeyboardEvent e) {
    print('pressed a key');

    if (e.keyCode == KeyCode.SPACE) {
      print('pressed space');

      if (started) {
        resetwatch();
      } else {
        startwatch();
      }

      started = !started; // A quick way to switch between true and false.
    }
  });
}

window window. .

KeyEvent, . .

+6

All Articles