如何在 flutter 中从 PDA 扫描仪设备获取条码

问题描述 投票:0回答:0

我的应用程序安装在各种类型的 PDA 设备上(如 datalogic、Honeywell、zkc 等) 我想从这些设备上扫描条形码。所以关于这个问题,我使用 RawKeyboardListener 就像下面的代码:


import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  static const String _title = 'RawKeyboardListener';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: const MyWidget(),
      ),
    );
  }
}

class MyWidget extends StatefulWidget {
  const MyWidget({Key? key}) : super(key: key);

  @override
  State<MyWidget> createState() => MyWidgetState();
}

class MyWidgetState extends State<MyWidget> {
  final FocusNode _focusNode = FocusNode();

  String _chars = '';

  String? barcode;

  @override
  void dispose() {
    _focusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    FocusScope.of(context).requestFocus(_focusNode);
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      child: RawKeyboardListener(
        focusNode: _focusNode,
        onKey: (RawKeyEvent event) {
          if (event is RawKeyDownEvent || event is RawKeyUpEvent) {
            if (event.physicalKey == PhysicalKeyboardKey.enter) {
              setState(() {
                barcode = _chars;
                _chars = '';
              });
            } else {
              _chars += event.data.keyLabel;
            }
          }
        },
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              'Barcode: $barcode',
            ),
          ],
        ),
      ),
    );
  }
}

此代码在通过 PDA 扫描仪扫描条形码时调用

onKey
回调,但条形码 (
event.data.keyLabel
) 在 datalogic PDA 扫描仪设备上为空。

此代码适用于手持扫描仪。 我看到了这个问题,但它对我不起作用。

如何从所有类型的 PDA 扫描仪获取条码?

flutter dart barcode-scanner
© www.soinside.com 2019 - 2024. All rights reserved.