My app installs on types of PDA devices (like datalogic, Honeywell, zkc, etc.) I want to get the barcode scanned from these devices. So about this issue, I use RawKeyboardListener like the following code:
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',
),
],
),
),
);
}
}
This code invokes an onKey callback when scanning the barcode via the PDA scanner, But the barcode (event.data.keyLabel) is empty on datalogic PDA scanner device.
This code works with a handheld scanner as true. I saw this question but it doesn't work for me.
How do I get barcodes from all types of PDA scanners?