Hoang Trung Nguyen
Hoang Trung Nguyen

Reputation: 509

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?

Upvotes: 0

Views: 107

Answers (1)

Omar Fayad
Omar Fayad

Reputation: 1793

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

Upvotes: 1

Related Questions