A way to completely close the keyboard without losing textfield focus

540 views Asked by At

Is there a way to completely close the keyboard without losing textfield focus? I'm using textfield to capture the result provided by a physical barcode reader built into the smartphone, it's in the return value, but I want to hide the keyboard. I tried many methods, but I couldn't find a good solution.

Your final solution was the following code. However, since there is no state management in the application, the keyboard opens and closes quickly every time the page is refreshed.

 @override
 Widget build(BuildContext context) {

  SystemChannels.textInput.invokeMethod("TextInput.hide");
  return Scaffold(..
2

There are 2 answers

1
Jasmin Sojitra On

To hide the keyboard and keep the cursor visible, set readOnly to true and show the cursor to true

TextFormField(
  showCursor: true,
  readOnly: true),

See flutter/issues/#16863

2
Piotr On

You can set keyboardType: parameter to TextInputType.none. This will retain focus. Keep access as the TextField is still editable but no keyboard is shown.