Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to detect keyboard press Enter?

Tags:

flutter

dart

TextEditingController.addListener() registers a callback for when the text changes. This seems to also be triggered by pressing the Enter button, opening/closing the keyboard (changing focus).

How do i register that it was the enter that was pressed so i can, for example, invoke an API?

The current way i achieve this is by listening on the FocusNode to detect focus change. Focus is removed from the FocusNode when pressing enter, and the keyboard closes. Is this the right way to do it?

like image 990
Jakob Kristensen Avatar asked Feb 11 '18 11:02

Jakob Kristensen


People also ask

How do you handle keyboard events in Flutter?

For text entry, consider using a EditableText, which integrates with on-screen keyboards and input method editors (IMEs). Creates a widget that receives raw keyboard events. For text entry, consider using a EditableText, which integrates with on-screen keyboards and input method editors (IMEs).

How do you show the keyboard in TextField in Flutter?

TextField is a very common widget in Flutter. When you click on the TextField it opens up the on-screen keyboard. To hide/dismiss the keyboard you have to press the back button in Android and the done button (inside the onscreen keyboard) in iOS.


1 Answers

There is a onSubmitted property which accepts a ValueChanged callback. onSubmitted is triggered once the user press done after editing.

Hope that helps!

like image 162
Hemanth Raj Avatar answered Oct 06 '22 15:10

Hemanth Raj