diff --git a/lib/barcode.dart b/lib/barcode.dart index 1fb9df39..9f608a33 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -1,3 +1,4 @@ +import 'package:InvenTree/widget/dialogs.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:qr_utils/qr_utils.dart'; @@ -23,8 +24,13 @@ Future scanQrCode(BuildContext context) async { // Look for JSON data in the result... final data = json.decode(result); + showProgressDialog(context, "Querying Server", "Sending barcode data to server"); + InvenTreeAPI().post("barcode/", body: data).then((var response) { + // Close the progress dialog + Navigator.pop(context); + if (response.statusCode != 200) { showDialog( context: context, @@ -93,7 +99,13 @@ void _handleBarcode(BuildContext context, Map data) { if (id != null) { // Try to open a stock location... + + showProgressDialog(context, "Loading data", "Requesting stock location information from server"); + InvenTreeStockLocation().get(id).then((var loc) { + + hideProgressDialog(context); + if (loc is InvenTreeStockLocation) { Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc))); } @@ -105,7 +117,13 @@ void _handleBarcode(BuildContext context, Map data) { id = data['stockitem']['id'] ?? null; if (id != null) { + + showProgressDialog(context, "Loading data", "Requesting stock item information from server"); + InvenTreeStockItem().get(id).then((var item) { + + hideProgressDialog(context); + Navigator.push(context, MaterialPageRoute(builder: (context) => StockDetailWidget(item))); }); } @@ -114,7 +132,13 @@ void _handleBarcode(BuildContext context, Map data) { id = data['part']['id'] ?? null; if (id != null) { + + showProgressDialog(context, "Loading data", "Requesting part information from server"); + InvenTreePart().get(id).then((var part) { + + hideProgressDialog(context); + Navigator.push(context, MaterialPageRoute(builder: (context) => PartDetailWidget(part))); }); diff --git a/lib/widget/dialogs.dart b/lib/widget/dialogs.dart new file mode 100644 index 00000000..5daa7092 --- /dev/null +++ b/lib/widget/dialogs.dart @@ -0,0 +1,21 @@ + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +void showProgressDialog(BuildContext context, String title, String description) { + showDialog( + context: context, + barrierDismissible: false, + child: SimpleDialog( + title: Text(title), + children: [ + CircularProgressIndicator(), + Text(description), + ], + ) + ); +} + +void hideProgressDialog(BuildContext context) { + Navigator.pop(context); +} \ No newline at end of file