Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.