2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 10:15:32 +00:00

Barcode refactor (#381)

* Simplify barcode scanning interface

* Use consistent colors

* Fix notches

* Remove old comment
This commit is contained in:
Oliver
2023-06-24 21:06:08 +10:00
committed by GitHub
parent e9eb84eace
commit 925966c627
8 changed files with 45 additions and 50 deletions

View File

@ -30,11 +30,25 @@ import "package:inventree/widget/supplier_part_detail.dart";
/*
* Return a new BarcodeController instance
* Launch a barcode scanner with a particular context and handler.
*
* - Can be called with a custom BarcodeHandler instance, or use the default handler
* - Returns a Future which resolves when the scanner is dismissed
* - The provided BarcodeHandler instance is used to handle the scanned barcode
*/
InvenTreeBarcodeController barcodeController(BarcodeHandler handler) {
// TODO: Make this configurable
return CameraBarcodeController(handler);
Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) async {
// Default to generic scan handler
handler ??= BarcodeScanHandler();
InvenTreeBarcodeController controller = CameraBarcodeController(handler);
return Navigator.of(context).push(
PageRouteBuilder(
pageBuilder: (context, _, __) => controller,
opaque: false,
)
);
}
@ -525,13 +539,6 @@ class UniqueBarcodeHandler extends BarcodeHandler {
}
Future<void> scanQrCode(BuildContext context) async {
Navigator.push(context, MaterialPageRoute(builder: (context) => barcodeController(BarcodeScanHandler())));
return;
}
SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state, String barcode, String model, int pk) {
if (barcode.isEmpty) {
@ -552,13 +559,7 @@ SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state,
state.refresh(context);
});
});
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => barcodeController(handler)
)
);
scanBarcode(context, handler: handler);
}
);
} else {