0

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(..
VolkanUstekidag
  • 345
  • 2
  • 8

2 Answers2

0

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

Jasmin Sojitra
  • 1,090
  • 10
  • 24
  • This is not a solution for me. Because the barcode reading process functions like a keyboard operation. I can't read barcode if I just do read as true. – VolkanUstekidag Jun 03 '22 at 07:48
0

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.

Piotr
  • 545
  • 4
  • 13