4

How can I collect chars from external keyboard and append to a var without having a text field? Im trying to setup a Bluetooth/USB barcode scanner to automatically to something when scanned but not that you have to click a field (or see one) And have a credit card reader Automatically do everything in the background..

RawSlugs
  • 520
  • 4
  • 11
  • Hi there..could you manage to connect the usb barcode scanner?? I'm starting to try using one so i'm garhering infos but all i found so far is this post . Thanks – Vincenzo Oct 18 '20 at 07:18

2 Answers2

9

RawKeyboardListener allows to do that https://docs.flutter.io/flutter/widgets/RawKeyboardListener-class.html

  var _focusNode = FocusNode();

  @override
  Widget build(BuildContext context) {

    return RawKeyboardListener(
        child: Text('raw keyboard input'),
        focusNode: _focusNode,
        onKey: _onRawKeyEvent,
      );
  }

  void _onRawKeyEvent(RawKeyEvent event) {
    ..
  }
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

I am in the same position and after some researches, I believe that RawKeyboardListener is actually not the best thing to use. Instead, there's a Widget called FocusScope that appears to be a perfect fit for this purpose. The best thing about this Widget is that its onKey event won't be triggered by any text field, nor will it be triggered by soft keyboard.

toyssamurai
  • 561
  • 4
  • 13
  • Hey I know it's a bit old but, can you provide a sample of how to implement that actually. I can't make any sense from the documentation. Also does this Widget prevent another widget from the next route from getting the focus? – malik_cesur Mar 31 '21 at 17:59