单击TextField /屏幕外的任何地方后,如何在颤动时隐藏软输入键盘?(How to hide soft input keyboard on flutter after clicking outs

编程入门 行业动态 更新时间:2024-10-22 14:44:42
单击TextField /屏幕外的任何地方后,如何在颤动时隐藏软输入键盘?(How to hide soft input keyboard on flutter after clicking outside TextField/anywhere on screen?)

目前我知道使用此代码隐藏软键盘的方法,通过任何小部件的onTap方法。

FocusScope.of(context).requestFocus(new FocusNode());

但我想通过单击TextField外部或屏幕上的任何位置来隐藏软键盘。 有没有什么方法可以做到这一点?

Currently I know the method of hiding the soft keyboard using this code, by onTap methods of any widget.

FocusScope.of(context).requestFocus(new FocusNode());

But I want to hide soft keyboard by clicking outside of TextField or anywhere on the screen. Is there any method in flutter to do this??

最满意答案

将整个屏幕包裹在GestureDetector中

new Scaffold( body: new GestureDetector( onTap: () { // call this method here to hide soft keyboard FocusScope.of(context).requestFocus(new FocusNode()); }, child: new Container( - - - ) )

You are doing it in wrong way, just try this simple method to hide soft keyboard. you just need to wrap you whole screen in GestureDetector method and onTap method write this code.

FocusScope.of(context).requestFocus(new FocusNode());

Here is the complete example:

new Scaffold( body: new GestureDetector( onTap: () { FocusScope.of(context).requestFocus(new FocusNode()); }, child: new Container( //rest of your code write here ) )

更多推荐

本文发布于:2023-07-08 20:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1080270.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   屏幕   键盘   地方   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!