Call a function when user press a Key from Keyboard in Flutter

Viewed 302

how can I call a function when the user presses a key from the keyboard ?

This is for Desktop development .

2 Answers

You can do it using Actions and shortcuts in flutter. These widgets work something like this :

How actions and shortcuts work

To get a more detailed information, please refer to the flutter docs here. These come under Advanced UI concepts.

I imagine you're using a TextField? It has the following property onChanged: ((newText) => {})

You can go ahead and use it like this:

onChanged: ((newText) => { yourFunction; }),

or

onChanged: ((newText) => { setState((){yourFunction;}); }),

Just to clarify, this will only update when the text changes. @Divyam Dhadwal seems to have a wild answer that might be more useful

Good luck my man! xx

Related