单击外部TextField /屏幕上的任何位置后,如何在颤动中隐藏软输入键盘? [英] How to hide soft input keyboard on flutter after clicking outside TextField/anywhere on screen?

查看:65
本文介绍了单击外部TextField /屏幕上的任何位置后,如何在颤动中隐藏软输入键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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());

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

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

推荐答案

以错误的方式进行操作,只需尝试使用这种简单的方法来隐藏软键盘即可。您只需要将整个屏幕包装在 GestureDetector 方法中,而 onTap 方法编写此代码即可。

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

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

以下是完整的示例:

new Scaffold(

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

这篇关于单击外部TextField /屏幕上的任何位置后,如何在颤动中隐藏软输入键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆