1

The Focus widget in Flutter can detect and handle KeyEvents. However, it will trigger on both key down and up events (so it calls its assigned callback twice for each press). Given a KeyEvent, how can I detect if it was a key down or up event so I can make the callback only react to one of those two events?

Thanks!

1 Answer 1

4

This really needs to be in the docs.

The KeyEvent passed is really one of the few subclasses that include KeyDownEvent and KeyUpEvent so you can check the type with

if(event is KeyDownEvent) {
  // ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.