2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 02:05:29 +00:00

Barcode refactor (#363)

* Move barcode.dart

* Fix

* Refactoring barcode scanner code:

- Abstract the "controller" class (for future development)
- Break barcode scanning code out into multiple files
- Add CameraBarcodeController class (qr_code_scanner)

* Add await

* Make barcode scan delay configurable

* remove unused import

* Handle camera exceptions

* Improve sequencing for camera scanner

- Show loading overlay
- Prevent reload if view is no longer mounted

* Update docstring

* Update release notes
This commit is contained in:
Oliver
2023-06-11 09:41:26 +10:00
committed by GitHub
parent 45fe79daf0
commit b051aeccda
17 changed files with 592 additions and 312 deletions

View File

@ -8,7 +8,7 @@
import "package:flutter_test/flutter_test.dart";
import "package:inventree/api.dart";
import "package:inventree/barcode.dart";
import "package:inventree/barcode/barcode.dart";
import "package:inventree/helpers.dart";
import "package:inventree/user_profile.dart";
@ -57,7 +57,7 @@ void main() {
test("Empty Barcode", () async {
// Handle an 'empty' barcode
await handler.processBarcode(null, "");
await handler.processBarcode("");
debugContains("Scanned barcode data: ''");
debugContains("showSnackIcon: 'Barcode scan error'");
@ -68,7 +68,7 @@ void main() {
test("Junk Data", () async {
// test scanning 'junk' data
await handler.processBarcode(null, "abcdefg");
await handler.processBarcode("abcdefg");
debugContains("Scanned barcode data: 'abcdefg'");
debugContains("showSnackIcon: 'No match for barcode'");
@ -76,7 +76,7 @@ void main() {
test("Invalid StockLocation", () async {
// Scan an invalid stock location
await handler.processBarcode(null, '{"stocklocation": 999999}');
await handler.processBarcode('{"stocklocation": 999999}');
debugContains("Scanned barcode data: '{\"stocklocation\": 999999}'");
debugContains("showSnackIcon: 'No match for barcode'");
@ -97,7 +97,7 @@ void main() {
var handler = StockItemScanIntoLocationHandler(item!);
await handler.processBarcode(null, '{"stocklocation": 7}');
await handler.processBarcode('{"stocklocation": 7}');
// Check the location has been updated
await item.reload();
assert(item.locationId == 7);
@ -105,7 +105,7 @@ void main() {
debugContains("Scanned stock location 7");
// Scan into a new location
await handler.processBarcode(null, '{"stocklocation": 1}');
await handler.processBarcode('{"stocklocation": 1}');
await item.reload();
assert(item.locationId == 1);
@ -125,7 +125,7 @@ void main() {
// Scan multiple items into this location
for (int id in [1, 2, 11]) {
await handler.processBarcode(null, '{"stockitem": ${id}}');
await handler.processBarcode('{"stockitem": ${id}}');
var item = await InvenTreeStockItem().get(id) as InvenTreeStockItem?;
@ -150,12 +150,12 @@ void main() {
var handler = ScanParentLocationHandler(location!);
// Scan into new parent location
await handler.processBarcode(null, '{"stocklocation": 1}');
await handler.processBarcode('{"stocklocation": 1}');
await location.reload();
assert(location.parentId == 1);
// Scan back into old parent location
await handler.processBarcode(null, '{"stocklocation": 4}');
await handler.processBarcode('{"stocklocation": 4}');
await location.reload();
assert(location.parentId == 4);