1

Is there a way to have a text field which when having the focus does not show the virtual keyboard? I need this to be able to capture the result delivered by a physical barcode reader built into the smartphone. I've seen solutions that recommend passing focus to another node, but that way it couldn't capture the barcode, and I've also seen that it can be used:

SystemChannels.textInput.invokeMethod ('TextInput.hide');

But for some reason it doesn't hide the keyboard.

Victor Ortiz
  • 791
  • 1
  • 12
  • 23
  • You can hide the keyboard whenever required and show it again using single statement – Sanjay Sharma Jun 03 '20 at 22:04
  • try this [https://stackoverflow.com/a/56946311/5665870](https://stackoverflow.com/a/56946311/5665870) if >= Flutter v1.7.8+hotfix.2 – Sphinx Jun 03 '20 at 23:19

1 Answers1

2

Use this library flutter_barcode_listener

It works like the following.

  1. listen for physical keyboard raw key up event
  2. filter out only 'REAL' characters (ASCII codes lower than 256, without special characters except enter)
  3. on each new key check if previous key is older than bufferDuration, if it's older clear internal buffer
  4. check if new key is enter key, if it is call onBarcodeScanned callback and clear buffer
  5. if it's not enter key just append it to internal buffer;

In your code you can wrap the widgets that depends on the scanner data with the BarcodeKeyboardListener and it will look something like this:

child: BarcodeKeyboardListener(
        bufferDuration: Duration(milliseconds: 200),
        onBarcodeScanned: (barcode) {
          if (!visible) return;
          print(barcode);
          setState(() {
            _barcode = barcode;
          });
        },
        child: SomeWidget(
Yves Boutellier
  • 1,286
  • 9
  • 19