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.

2

1 Answer 1

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(
1
  • this is not working for me.
    – Kokila
    Sep 5, 2022 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.