diff --git a/lib/barcode.dart b/lib/barcode.dart index a17b8091..e28c2688 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -65,21 +65,26 @@ class BarcodeHandler { ); } - Future processBarcode(BuildContext context, QRViewController _controller, String barcode) { + Future processBarcode(BuildContext context, QRViewController _controller, String barcode, {String url = "barcode/", bool show_dialog = false}) { this._context = context; this._controller = _controller; print("Scanned barcode data: ${barcode}"); - showProgressDialog(context, "Scanning", "Sending barcode data to server"); + if (show_dialog) { + showProgressDialog(context, "Scanning", "Sending barcode data to server"); + } // Send barcode request to server InvenTreeAPI().post( - "barcode/", + url, body: { "barcode": barcode } ).then((var response) { - hideProgressDialog(context); + + if (show_dialog) { + hideProgressDialog(context); + } if (response.statusCode != 200) { showErrorDialog( @@ -112,7 +117,11 @@ class BarcodeHandler { }).timeout( Duration(seconds: 5) ).catchError((error) { - hideProgressDialog(context); + + if (show_dialog) { + hideProgressDialog(context); + } + showErrorDialog( context, "Error", diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index c9bbc801..6d7d1a01 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -149,7 +149,7 @@ class InvenTreeModel { } // POST data to update the model - Future update(BuildContext context, {Map values}) async { + Future update(BuildContext context, {Map values, bool show_dialog = false}) async { var addr = path.join(URL, pk.toString()); @@ -157,13 +157,17 @@ class InvenTreeModel { addr += "/"; } - showProgressDialog(context, "Updating ${NAME}", "Sending data to server"); + if (show_dialog) { + showProgressDialog(context, "Updating ${NAME}", "Sending data to server"); + } var response = await api.patch(addr, body: values) .timeout(Duration(seconds: 10)) .catchError((e) { - hideProgressDialog(context); + if (show_dialog) { + hideProgressDialog(context); + } if (e is TimeoutException) { showErrorDialog(context, "Timeout", "No response from server"); @@ -176,7 +180,9 @@ class InvenTreeModel { if (response == null) return false; - hideProgressDialog(context); + if (show_dialog) { + hideProgressDialog(context); + } if (response.statusCode != 200) { print("Error updating ${NAME}: Status code ${response.statusCode}");