mirror of
https://github.com/inventree/inventree-app.git
synced 2026-11-27 15:59:09 +00:00
Interpret ECI character-set marker in scanned 2D barcodes (#907)
This commit is contained in:
1 parent
197de6aa16
commit
085dad4c2d
3 files changed
+142
-1
No files matched your search
@@ -16,6 +16,7 @@ import "package:inventree/l10.dart";
|
||||
|
||||
import "package:inventree/barcode/handler.dart";
|
||||
import "package:inventree/barcode/controller.dart";
|
||||
import "package:inventree/barcode/eci.dart";
|
||||
|
||||
/*
|
||||
* Barcode controller which uses the device's camera to scan barcodes.
|
||||
@@ -128,7 +129,7 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
||||
});
|
||||
}
|
||||
|
||||
String barcode = result.barcodes.first.rawValue ?? "";
|
||||
String barcode = scannedValue(result.barcodes.first);
|
||||
|
||||
if (barcode.isEmpty) {
|
||||
// TODO: Error message "empty barcode"
|
||||
@@ -157,6 +158,29 @@ class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Text value of a scanned barcode.
|
||||
* For 2D codes, an ECI character-set marker that the scanner left in the
|
||||
* data is interpreted rather than passed on (see barcode/eci.dart).
|
||||
*/
|
||||
String scannedValue(Barcode code) {
|
||||
final decoded = switch (code.rawDecodedBytes) {
|
||||
DecodedBarcodeBytes(:final bytes) => bytes,
|
||||
DecodedVisionBarcodeBytes(:final bytes) => bytes,
|
||||
null => null,
|
||||
};
|
||||
|
||||
switch (code.format) {
|
||||
case BarcodeFormat.dataMatrix:
|
||||
case BarcodeFormat.qrCode:
|
||||
case BarcodeFormat.aztec:
|
||||
case BarcodeFormat.pdf417:
|
||||
return decodeEciPrefixed(code.rawValue, decoded);
|
||||
default:
|
||||
return code.rawValue ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
void onControllerCreated(CameraController? controller, Exception? error) {
|
||||
if (error != null) {
|
||||
sentryReportError(
|
||||
|
||||
Reference in new issue
Block a user