简体   繁体   中英

Dismiss the keyboard after all fields in a form are filled in Flutter?

I am making a sign-up form. My problem is when the user fills the last field in my form and hit enter on the keyboard, but the keyboard does not dismiss. Is there any way to dismiss the keyboard?

If you want to dismiss the keyboard when the user clicks anywhere on the screen:

wrap the scaffold with GestureDetector:

GestureDetector(
  onTap: () {
    setState(() {
      FocusScope.of(context).requestFocus(new FocusNode());
    });
  },
  child: Scaffold());

If you want to dismiss the keyboard when the user fills the last textField: track the textfields controllers and when you are at the last one use yourControllerName.unfocus();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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