scanBarcode static method
Example: Barcode scanner
Implementation
static Future<void> scanBarcode() async {
print('=== Barcode Scanner Example ===');
final sub = PaxSdk.onReadSuccess.listen((code) {
print('Scanned: $code');
});
final started = await PaxSdk.startScanner(
scannerType: 'REAR',
timeoutMs: 30000,
);
if (started['success'] != true) {
print('Failed to start scanner: ${started['error']}');
await sub.cancel();
return;
}
print('Scanner started. Press side scan button, or wait for timeout.');
// In a real app, keep the subscription until you call stopScanner().
await Future.delayed(const Duration(seconds: 30));
await PaxSdk.stopScanner();
await sub.cancel();
print('Scanner stopped');
}