RawSlugs
RawSlugs

Reputation: 708

External keyboard in flutter support

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..

Upvotes: 4

Views: 5177

Answers (2)

toyssamurai
toyssamurai

Reputation: 711

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.

Upvotes: 0

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657058

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) {
    ..
  }

Upvotes: 9

Related Questions