From 0c6ce778e759ceb6806927a553d1ece01271dc39 Mon Sep 17 00:00:00 2001 From: DPohorielov Date: Mon, 5 Aug 2024 08:37:58 -0400 Subject: [PATCH 1/2] Correctly pass the widget tree to the KeyboardListener so that it wraps the listening area. --- packages/usb_keyboard_scanner/README.md | 4 +++- packages/usb_keyboard_scanner/example/main.dart | 4 +++- .../lib/src/usb_keyboard_scanner.dart | 10 +++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/usb_keyboard_scanner/README.md b/packages/usb_keyboard_scanner/README.md index af3f2da..43697e3 100644 --- a/packages/usb_keyboard_scanner/README.md +++ b/packages/usb_keyboard_scanner/README.md @@ -18,6 +18,8 @@ BarcodeScannerWidget( configuration: const ScannerConfiguration( enableFormats: {}, // supported formats are determined by the scanner itself ), - scanners: [UsbKeyboardScanner()], + scanners: [UsbKeyboardScanner( + child: content, + )], ); ``` \ No newline at end of file diff --git a/packages/usb_keyboard_scanner/example/main.dart b/packages/usb_keyboard_scanner/example/main.dart index b92741a..236be1e 100644 --- a/packages/usb_keyboard_scanner/example/main.dart +++ b/packages/usb_keyboard_scanner/example/main.dart @@ -63,7 +63,9 @@ class _MyHomePageState extends State { configuration: const ScannerConfiguration( enableFormats: {}, // enableFormats unfortunately does not work with the UsbKeyboardScanner, this configuration is managed by the device itself ), - scanners: [UsbKeyboardScanner()], + scanners: [UsbKeyboardScanner( + child: const SizedBox(), + )], ), ); } diff --git a/packages/usb_keyboard_scanner/lib/src/usb_keyboard_scanner.dart b/packages/usb_keyboard_scanner/lib/src/usb_keyboard_scanner.dart index 4549071..5026159 100644 --- a/packages/usb_keyboard_scanner/lib/src/usb_keyboard_scanner.dart +++ b/packages/usb_keyboard_scanner/lib/src/usb_keyboard_scanner.dart @@ -8,7 +8,8 @@ import 'package:flutter/material.dart'; /// Please follow the installation instructions in /// [https://pub.dev/packages/fast_barcode_scanner] class UsbKeyboardScanner implements BarcodeScanner { - int maxCharacterInputIntervalMs; + final int maxCharacterInputIntervalMs; + final Widget child; late ValueChanged _onScan; late FocusNode _focusNode; @@ -17,7 +18,10 @@ class UsbKeyboardScanner implements BarcodeScanner { var isRunning = true; - UsbKeyboardScanner({this.maxCharacterInputIntervalMs = 50}); + UsbKeyboardScanner({ + this.maxCharacterInputIntervalMs = 50, + required this.child, + }); @override Widget? buildUI(ScannerConfiguration configuration, BuildContext context) => @@ -25,7 +29,7 @@ class UsbKeyboardScanner implements BarcodeScanner { focusNode: _focusNode, autofocus: true, onKeyEvent: _onKeyEvent, - child: const SizedBox(), + child: child, ); @override From dbb8f385f9d78e6c3923f1daac2057d5a17cb471 Mon Sep 17 00:00:00 2001 From: DPohorielov Date: Mon, 5 Aug 2024 08:51:49 -0400 Subject: [PATCH 2/2] Fixed main example to match UsbKeyboardScanner parameters --- example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 74b5810..141be9d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -50,7 +50,7 @@ class _MyHomePageState extends State { UnitechBarcodeScanner(), BlueBirdBarcodeScanner(), ZebraBarcodeScanner('my_profile'), - UsbKeyboardScanner(), + UsbKeyboardScanner(child: const SizedBox()), ]; @override