2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 50 deletions

View File

@ -349,11 +349,7 @@ class APIFormField {
);
});
Navigator.push(
context,
MaterialPageRoute(builder: (context) => barcodeController(handler)
)
);
scanBarcode(context, handler: handler);
},
),
)

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 {

View File

@ -8,6 +8,7 @@
import "package:flutter/material.dart";
import "package:inventree/api.dart";
import "package:inventree/app_colors.dart";
import "package:inventree/helpers.dart";
@ -112,17 +113,17 @@ class InvenTreeStatusCode {
switch (color_name.toLowerCase()) {
case "success":
return Colors.green;
return COLOR_SUCCESS;
case "primary":
return Colors.blue;
return COLOR_PROGRESS;
case "secondary":
return Colors.grey;
case "dark":
return Colors.black;
case "danger":
return Colors.red;
return COLOR_DANGER;
case "warning":
return Colors.orange;
return COLOR_WARNING;
case "info":
return Colors.lightBlue;
default:

View File

@ -181,21 +181,18 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
),
),
onTap: () {
if (!allowed) {
showSnackIcon(
L10().permissionRequired,
icon: FontAwesomeIcons.circleExclamation,
success: false,
);
return;
}
if (callback != null) {
callback();
}
},
);
}

View File

@ -91,11 +91,9 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
child: FaIcon(FontAwesomeIcons.qrcode),
label: L10().barcodeScanItem,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) =>
barcodeController(
StockLocationScanInItemsHandler(location!)))
scanBarcode(
context,
handler: StockLocationScanInItemsHandler(location!),
).then((value) {
refresh(context);
});
@ -111,11 +109,9 @@ class _LocationDisplayState extends RefreshableState<LocationDisplayWidget> {
child: FaIcon(FontAwesomeIcons.qrcode),
label: L10().transferStockLocation,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) =>
barcodeController(ScanParentLocationHandler(location!))
)
scanBarcode(
context,
handler: ScanParentLocationHandler(location!),
).then((value) {
refresh(context);
});

View File

@ -102,15 +102,22 @@ mixin BaseWidgetProperties {
iconSize: iconSize,
onPressed: () {
if (InvenTreeAPI().checkConnection()) {
scanQrCode(context);
scanBarcode(context);
}
},
)
];
return BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 20,
shape: AutomaticNotchedShape(
RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(40)),
),
),
notchMargin: 10,
child: IconTheme(
data: IconThemeData(color: Theme.of(context).colorScheme.onPrimary),
child: Row(

View File

@ -165,12 +165,9 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> {
child: Icon(Icons.qr_code_scanner),
label: L10().scanIntoLocation,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) =>
barcodeController(
StockItemScanIntoLocationHandler(widget.item))
)
scanBarcode(
context,
handler: StockItemScanIntoLocationHandler(widget.item)
).then((ctx) {
refresh(context);
});