简体   繁体   English

颤动:如何检测键盘输入?

[英]Flutter: How to detect keyboard press Enter?

TextEditingController.addListener() registers a callback for when the text changes. TextEditingController.addListener()在文本更改时注册回调。 This seems to also be triggered by pressing the Enter button, opening/closing the keyboard (changing focus). 这似乎也可以通过按Enter键,打开/关闭键盘(更改焦点)来触发。

How do i register that it was the enter that was pressed so i can, for example, invoke an API? 我如何注册它是被按下的输入,所以我可以,例如,调用API?

The current way i achieve this is by listening on the FocusNode to detect focus change. 我实现这一目标的当前方式是通过监听FocusNode来检测焦点变化。 Focus is removed from the FocusNode when pressing enter, and the keyboard closes. 按Enter FocusNode时焦点从FocusNode移除,键盘关闭。 Is this the right way to do it? 这是正确的方法吗?

There is a onSubmitted property which accepts a ValueChanged callback. 有一个onSubmitted属性接受ValueChanged回调。 onSubmitted is triggered once the user press done after editing. 一旦用户在编辑后按完成,就会触发onSubmitted

Hope that helps! 希望有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM