External keyboard in flutter support

前端 未结 2 1475
轻奢々
轻奢々 2020-12-19 22:00

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 someth

相关标签:
2条回答
  • 2020-12-19 22:35

    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.

    0 讨论(0)
  • 2020-12-19 22:36

    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) {
        ..
      }
    
    0 讨论(0)
提交回复
热议问题