diff --git a/lib/barcode.dart b/lib/barcode.dart index 8345dea5..924c0e6f 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -1,7 +1,9 @@ import 'package:InvenTree/widget/dialogs.dart'; +import 'package:InvenTree/widget/snacks.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:one_context/one_context.dart'; import 'package:qr_code_scanner/qr_code_scanner.dart'; @@ -139,6 +141,19 @@ class BarcodeScanHandler extends BarcodeHandler { @override Future onBarcodeUnknown(Map data) { + + showSnackIcon( + "No barcode", + icon: FontAwesomeIcons.exclamationCircle, + onTap: () { + print("Tappity"); + }, + success: true, + ); + + _controller.resumeCamera(); + + /* showErrorDialog( _context, data['error'] ?? '', @@ -149,6 +164,8 @@ class BarcodeScanHandler extends BarcodeHandler { _controller.resumeCamera(); } ); + + */ } @override @@ -385,14 +402,7 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler { @override Future onBarcodeMatched(Map data) { // If the barcode points to a 'stocklocation', great! - if (!data.containsKey('stocklocation')) { - showErrorDialog( - _context, - "Invalid Barcode", - "Barcode does not match a Stock Location", - onDismissed: _controller.resumeCamera, - ); - } else { + if (data.containsKey('stocklocation')) { // Extract location information int location = data['stocklocation']['pk'] as int; @@ -402,11 +412,35 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler { _controller.dispose(); Navigator.of(_context).pop(); }); + } else { + // Display a snack bar with the error + OneContext().showSnackBar(builder: (context) => SnackBar( + content: Text("This was not a stock item!") + )); } } } +class StockLocationScanInItemsHandler extends BarcodeHandler { + /** + * Barcode handler for scanning stock item(s) into the specified StockLocation + */ + + final InvenTreeStockLocation location; + + StockLocationScanInItemsHandler(this.location); + + @override + String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanItem; + + @override + Future onBarcodeMatched(Map data) { + print("TODO, YO!"); + } +} + + Future scanQrCode(BuildContext context) async { Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeQRView(BarcodeScanHandler()))); diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 88d06e43..6d1418f2 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -91,7 +91,6 @@ class _PartDisplayState extends RefreshableState { final bool result = await part.update(context, values: values); showSnackIcon( - refreshableKey, result ? "Part edited" : "Part editing failed", success: result ); diff --git a/lib/widget/snacks.dart b/lib/widget/snacks.dart index c01e3363..753ac12e 100644 --- a/lib/widget/snacks.dart +++ b/lib/widget/snacks.dart @@ -11,26 +11,44 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:one_context/one_context.dart'; -void showSnackIcon(GlobalKey key, String text, {IconData icon, bool success}) { +void showSnackIcon(String text, {IconData icon, Function onTap, bool success}) { - // Hide the current snackbar - key.currentState.hideCurrentSnackBar(); + OneContext().hideCurrentSnackBar(); + + Color backgroundColor; + + // Make some selections based on the "success" value + if (success == true) { + backgroundColor = Colors.lightGreen; + + // Unspecified icon? + if (icon == null) { + icon = FontAwesomeIcons.checkCircle; + } + + } else if (success == false) { + backgroundColor = Colors.deepOrange; + + if (icon == null) { + icon = FontAwesomeIcons.timesCircle; + } - // If icon not specified, use the success status - if (icon == null) { - icon = (success == false) ? FontAwesomeIcons.timesCircle : FontAwesomeIcons.checkCircle; } - key.currentState.showSnackBar( - SnackBar( - content: Row( + OneContext().showSnackBar(builder: (context) => SnackBar( + content: GestureDetector( + child: Row( children: [ Text(text), Spacer(), FaIcon(icon) - ] + ], ), - ) - ); + onTap: onTap, + ), + backgroundColor: backgroundColor, + )); + } \ No newline at end of file diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index a7c2e2f5..f970718f 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -148,7 +148,6 @@ class _StockItemDisplayState extends RefreshableState { void _stockUpdateMessage(bool result) { showSnackIcon( - refreshableKey, result ? "Stock item updated" : "Stock item updated failed", success: result ); diff --git a/lib/widget/stock_item_test_results.dart b/lib/widget/stock_item_test_results.dart index b29ab2fd..7704f6a4 100644 --- a/lib/widget/stock_item_test_results.dart +++ b/lib/widget/stock_item_test_results.dart @@ -56,7 +56,6 @@ class _StockItemTestResultDisplayState extends RefreshableState