user4246398
user4246398

Reputation: 121

flutter :Hide keyboard for a TextField

I have a search textfield and when I enter the field I see the keyboard. I would like to go to another screen when the user click/select the field instead of showig the keyboard.

How do I hide the keyboard and go go to another screen when a user click on the field.

Basically, I want to create the action that Gmail is doing when you click the search button.

This is snippet of the textfield..

Container(
  color: Palette.WHITE,
  child: Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: <Widget>[
       TextField(
          controller: _textSearchController,
          onSubmitted: (val) {}
           decoration: InputDecoration(...)
        )
       ],
  )
)

Thanks for your help

Upvotes: 0

Views: 470

Answers (3)

Baker
Baker

Reputation: 28060

If you want to not open a keyboard and use your TextField as basically a button to go to another screen:

TextField(
  readOnly: true,
  onTap: () => Navigator.push(context, MaterialPageRoute(builder: (context) => SomeOtherScreen())),
),

Upvotes: 0

Priyesh
Priyesh

Reputation: 1313

Have you tried to hide keyboard at onSubmit method like below?

onSubmitted: (val) {
     FocusScope.of(context).requestFocus(FocusNode());
  }

Let me know if it works.

Upvotes: 1

Calvin Gonsalves
Calvin Gonsalves

Reputation: 2030

There is a onTap property on the TextField widget and you can use this to navigate to a different route. If you want to disable typing, you can set the readOnly property to true.

If you want to re-create the search button on Gmail, you can take a look at the Search Delegate showMenu method that flutter provides

Upvotes: 0

Related Questions