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

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

This is for Desktop development .



Solution 1:[1]

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.

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Divyam Dhadwal
Solution 2 Percent.twof