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( scanBarcode(context, handler: handler);
context,
MaterialPageRoute(builder: (context) => barcodeController(handler)
)
);
}, },
), ),
) )

View File

@ -18,4 +18,4 @@ Color get COLOR_ACTION {
const Color COLOR_WARNING = Color.fromRGBO(250, 150, 50, 1); const Color COLOR_WARNING = Color.fromRGBO(250, 150, 50, 1);
const Color COLOR_DANGER = Color.fromRGBO(200, 50, 75, 1); const Color COLOR_DANGER = Color.fromRGBO(200, 50, 75, 1);
const Color COLOR_SUCCESS = Color.fromRGBO(100, 200, 75, 1); const Color COLOR_SUCCESS = Color.fromRGBO(100, 200, 75, 1);
const Color COLOR_PROGRESS = Color.fromRGBO(50, 100, 200, 1); const Color COLOR_PROGRESS = Color.fromRGBO(50, 100, 200, 1);

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) { Future<Object?> scanBarcode(BuildContext context, {BarcodeHandler? handler}) async {
// TODO: Make this configurable
return CameraBarcodeController(handler); // 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) { SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state, String barcode, String model, int pk) {
if (barcode.isEmpty) { if (barcode.isEmpty) {
@ -552,13 +559,7 @@ SpeedDialChild customBarcodeAction(BuildContext context, RefreshableState state,
state.refresh(context); state.refresh(context);
}); });
}); });
scanBarcode(context, handler: handler);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => barcodeController(handler)
)
);
} }
); );
} else { } else {

View File

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

View File

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

View File

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

View File

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

View File

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