Ask Your Question
4

In Flutter, what is the process for turning off the default phone keyboard when the user clicks on a Text input?

asked 2021-06-03 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-01-16 09:00:00 +0000

lalupa gravatar image

To turn off the default phone keyboard when a user clicks on a Text input in Flutter, you can use the following code snippet:

  1. Create a TextEditingController object for the Text input:
TextEditingController _controller = TextEditingController();
  1. Use the FocusNode class to handle when the Text input has the focus:
FocusNode _focusNode = FocusNode();
  1. Wrap the Text input widget with a GestureDetector and set the onTap event to request focus on the Text input and hide the keyboard:
GestureDetector(
  onTap: () {
    _focusNode.requestFocus();
    FocusScope.of(context).requestFocus(FocusNode());
  },
  child: TextFormField(
    controller: _controller,
    focusNode: _focusNode,
    decoration: InputDecoration(
      hintText: "Enter text",
    ),
  ),
),

This will set the focus on the Text input and then remove focus, which will hide the keyboard.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-06-03 11:00:00 +0000

Seen: 11 times

Last updated: Jan 16 '23