diff --git a/lib/api_form.dart b/lib/api_form.dart index 19f539de..982039ab 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -349,11 +349,7 @@ class APIFormField { ); }); - Navigator.push( - context, - MaterialPageRoute(builder: (context) => barcodeController(handler) - ) - ); + scanBarcode(context, handler: handler); }, ), ) diff --git a/lib/app_colors.dart b/lib/app_colors.dart index 091718b4..feba6c09 100644 --- a/lib/app_colors.dart +++ b/lib/app_colors.dart @@ -18,4 +18,4 @@ Color get COLOR_ACTION { const Color COLOR_WARNING = Color.fromRGBO(250, 150, 50, 1); const Color COLOR_DANGER = Color.fromRGBO(200, 50, 75, 1); const Color COLOR_SUCCESS = Color.fromRGBO(100, 200, 75, 1); -const Color COLOR_PROGRESS = Color.fromRGBO(50, 100, 200, 1); \ No newline at end of file +const Color COLOR_PROGRESS = Color.fromRGBO(50, 100, 200, 1); diff --git a/lib/barcode/barcode.dart b/lib/barcode/barcode.dart index 6c3c592b..d87f34c3 100644 --- a/lib/barcode/barcode.dart +++ b/lib/barcode/barcode.dart @@ -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 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 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 { diff --git a/lib/inventree/status_codes.dart b/lib/inventree/status_codes.dart index 2d9b3c32..8edb4ea0 100644 --- a/lib/inventree/status_codes.dart +++ b/lib/inventree/status_codes.dart @@ -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: diff --git a/lib/widget/home.dart b/lib/widget/home.dart index bd5701c1..cb157112 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -181,21 +181,18 @@ class _InvenTreeHomePageState extends State with BaseWidgetPr ), ), onTap: () { - if (!allowed) { showSnackIcon( L10().permissionRequired, icon: FontAwesomeIcons.circleExclamation, success: false, ); - return; } if (callback != null) { callback(); } - }, ); } diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index bd43ab4e..b76586d6 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -91,11 +91,9 @@ class _LocationDisplayState extends RefreshableState { 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 { 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); }); diff --git a/lib/widget/refreshable_state.dart b/lib/widget/refreshable_state.dart index 462dda3f..e484265d 100644 --- a/lib/widget/refreshable_state.dart +++ b/lib/widget/refreshable_state.dart @@ -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( diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index c2830775..903d626f 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -165,12 +165,9 @@ class _StockItemDisplayState extends RefreshableState { 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); });