mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 05:15:42 +00:00 
			
		
		
		
	Snack bars for barcode actions
This commit is contained in:
		
							
								
								
									
										137
									
								
								lib/barcode.dart
									
									
									
									
									
								
							
							
						
						
									
										137
									
								
								lib/barcode.dart
									
									
									
									
									
								
							| @@ -45,28 +45,19 @@ class BarcodeHandler { | ||||
|     Future<void> onBarcodeUnknown(Map<String, dynamic> data) { | ||||
|       // Called when the server does not know about a barcode | ||||
|       // Override this function | ||||
|       showErrorDialog( | ||||
|         "Invalid Barcode", | ||||
|         "Barcode does not match any known item", | ||||
|         error: "Barcode Error", | ||||
|         icon: FontAwesomeIcons.barcode, | ||||
|         onDismissed: () { | ||||
|           _controller.resumeCamera(); | ||||
|         } | ||||
|       showSnackIcon( | ||||
|         I18N.of(OneContext().context).barcodeNoMatch, | ||||
|         success: false, | ||||
|         icon: FontAwesomeIcons.qrcode | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     Future<void> onBarcodeUnhandled(Map<String, dynamic> data) { | ||||
|       // Called when the server returns an unhandled response | ||||
|       showErrorDialog( | ||||
|           "Response Data", | ||||
|           data.toString(), | ||||
|           error: "Unknown Response", | ||||
|           onDismissed: () { | ||||
|       showServerError(I18N.of(OneContext().context).responseUnknown, data.toString()); | ||||
|  | ||||
|       _controller.resumeCamera(); | ||||
|     } | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     Future<void> processBarcode(BuildContext context, QRViewController _controller, String barcode, {String url = "barcode/"}) { | ||||
|       this._context = context; | ||||
| @@ -93,23 +84,22 @@ class BarcodeHandler { | ||||
|         final Map<String, dynamic> data = json.decode(response.body); | ||||
|  | ||||
|         if (data.containsKey('error')) { | ||||
|           _controller.resumeCamera(); | ||||
|           onBarcodeUnknown(data); | ||||
|         } else if (data.containsKey('success')) { | ||||
|           _controller.resumeCamera(); | ||||
|           onBarcodeMatched(data); | ||||
|         } else { | ||||
|           _controller.resumeCamera(); | ||||
|           onBarcodeUnhandled(data); | ||||
|         } | ||||
|       }).timeout( | ||||
|           Duration(seconds: 5) | ||||
|       ).catchError((error) { | ||||
|  | ||||
|         showErrorDialog( | ||||
|           I18N.of(OneContext().context).error, | ||||
|             error.toString(), | ||||
|             onDismissed: () { | ||||
|         showServerError(I18N.of(OneContext().context).error, error.toString()); | ||||
|         _controller.resumeCamera(); | ||||
|             } | ||||
|         ); | ||||
|  | ||||
|         return; | ||||
|       }); | ||||
|     } | ||||
| @@ -129,30 +119,10 @@ class BarcodeScanHandler extends BarcodeHandler { | ||||
|   Future<void> onBarcodeUnknown(Map<String, dynamic> data) { | ||||
|  | ||||
|     showSnackIcon( | ||||
|         "No barcode", | ||||
|         I18N.of(OneContext().context).barcodeNoMatch, | ||||
|         icon: FontAwesomeIcons.exclamationCircle, | ||||
|         actionText: "Details", | ||||
|         onAction: () { | ||||
|           print("Action!"); | ||||
|         }, | ||||
|         success: true, | ||||
|         success: false, | ||||
|     ); | ||||
|  | ||||
|     _controller.resumeCamera(); | ||||
|  | ||||
|     /* | ||||
|     showErrorDialog( | ||||
|         _context, | ||||
|         data['error'] ?? '', | ||||
|         data['plugin'] ?? 'No barcode plugin information', | ||||
|         error: "Barcode Error", | ||||
|         icon: FontAwesomeIcons.barcode, | ||||
|         onDismissed: () { | ||||
|           _controller.resumeCamera(); | ||||
|         } | ||||
|     ); | ||||
|  | ||||
|      */ | ||||
|   } | ||||
|  | ||||
|   @override | ||||
| @@ -175,7 +145,10 @@ class BarcodeScanHandler extends BarcodeHandler { | ||||
|           } | ||||
|         }); | ||||
|       } else { | ||||
|         // TODO - Show an error here! | ||||
|         showSnackIcon( | ||||
|           I18N.of(OneContext().context).invalidStockLocation, | ||||
|           success: false | ||||
|         ); | ||||
|       } | ||||
|  | ||||
|     } else if (data.containsKey('stockitem')) { | ||||
| @@ -188,7 +161,10 @@ class BarcodeScanHandler extends BarcodeHandler { | ||||
|           Navigator.push(_context, MaterialPageRoute(builder: (context) => StockDetailWidget(item))); | ||||
|         }); | ||||
|       } else { | ||||
|         // TODO - Show an error here! | ||||
|         showSnackIcon( | ||||
|             I18N.of(OneContext().context).invalidStockItem, | ||||
|             success: false | ||||
|         ); | ||||
|       } | ||||
|     } else if (data.containsKey('part')) { | ||||
|  | ||||
| @@ -200,9 +176,16 @@ class BarcodeScanHandler extends BarcodeHandler { | ||||
|           Navigator.push(_context, MaterialPageRoute(builder: (context) => PartDetailWidget(part))); | ||||
|         }); | ||||
|       } else { | ||||
|         // TODO - Show an error here! | ||||
|         showSnackIcon( | ||||
|             I18N.of(OneContext().context).invalidPart, | ||||
|             success: false | ||||
|         ); | ||||
|       } | ||||
|     } else { | ||||
|       showSnackIcon( | ||||
|         I18N.of(OneContext().context).barcodeUnknown, | ||||
|         success: false, | ||||
|         onAction: () { | ||||
|           showDialog( | ||||
|               context: _context, | ||||
|               child: SimpleDialog( | ||||
| @@ -216,6 +199,8 @@ class BarcodeScanHandler extends BarcodeHandler { | ||||
|               ) | ||||
|           ); | ||||
|         } | ||||
|       ); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| @@ -235,12 +220,10 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { | ||||
|   @override | ||||
|   Future<void> onBarcodeMatched(Map<String, dynamic> data) { | ||||
|     // If the barcode is known, we can't asisgn it to the stock item! | ||||
|     showErrorDialog( | ||||
|       "Barcode in Use", | ||||
|       "Barcode is already known", | ||||
|       onDismissed: () { | ||||
|         _controller.resumeCamera(); | ||||
|       } | ||||
|     showSnackIcon( | ||||
|       I18N.of(OneContext().context).barcodeInUse, | ||||
|       icon: FontAwesomeIcons.qrcode, | ||||
|       success: false | ||||
|     ); | ||||
|   } | ||||
|  | ||||
| @@ -249,14 +232,9 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { | ||||
|     // If the barcode is unknown, we *can* assign it to the stock item! | ||||
|  | ||||
|     if (!data.containsKey("hash")) { | ||||
|       showErrorDialog( | ||||
|         "Missing Data", | ||||
|         "Missing hash data from server", | ||||
|         onDismissed: () { | ||||
|           _controller.resumeCamera(); | ||||
|         } | ||||
|       ); | ||||
|       showServerError("Missing data", "Barcode hash data missing from response"); | ||||
|     } else { | ||||
|  | ||||
|       // Send the 'hash' code as the UID for the stock item | ||||
|       item.update( | ||||
|         _context, | ||||
| @@ -265,22 +243,22 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { | ||||
|         } | ||||
|       ).then((result) { | ||||
|         if (result) { | ||||
|           showInfoDialog( | ||||
|               _context, | ||||
|               "Barcode Set", | ||||
|               "Barcode assigned to stock item", | ||||
|               onDismissed: () { | ||||
|  | ||||
|           // Close the barcode scanner | ||||
|           _controller.dispose(); | ||||
|           Navigator.of(_context).pop(); | ||||
|               } | ||||
|  | ||||
|           showSnackIcon( | ||||
|             I18N.of(OneContext().context).barcodeAssigned, | ||||
|             success: true, | ||||
|             icon: FontAwesomeIcons.qrcode | ||||
|           ); | ||||
|         } else { | ||||
|           showErrorDialog( | ||||
|             "Server Error", | ||||
|             "Could not assign barcode", | ||||
|             onDismissed: () { | ||||
|               _controller.resumeCamera(); | ||||
|             } | ||||
|  | ||||
|           showSnackIcon( | ||||
|               I18N.of(OneContext().context).barcodeNotAssigned, | ||||
|               success: false, | ||||
|               icon: FontAwesomeIcons.qrcode | ||||
|           ); | ||||
|         } | ||||
|       }); | ||||
| @@ -393,14 +371,23 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler { | ||||
|       // Transfer stock to specified location | ||||
|       item.transferStock(location).then((response) { | ||||
|         print("Response: ${response.statusCode}"); | ||||
|  | ||||
|         // Close the scanner | ||||
|         _controller.dispose(); | ||||
|         Navigator.of(_context).pop(); | ||||
|  | ||||
|         showSnackIcon( | ||||
|           I18N.of(OneContext().context).barcodeScanIntoLocationSuccess, | ||||
|           success: true, | ||||
|         ); | ||||
|  | ||||
|       }); | ||||
|     } else { | ||||
|       // Display a snack bar with the error | ||||
|       OneContext().showSnackBar(builder: (context) => SnackBar( | ||||
|         content: Text("This was not a stock item!") | ||||
|       )); | ||||
|       showSnackIcon( | ||||
|         I18N.of(OneContext().context).invalidStockLocation, | ||||
|         success: false, | ||||
|       ); | ||||
|  | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
							
								
								
									
										2
									
								
								lib/l10n
									
									
									
									
									
								
							
							
								
								
								
								
								
							
						
						
									
										2
									
								
								lib/l10n
									
									
									
									
									
								
							 Submodule lib/l10n updated: f1e991199f...0e41299506
									
								
							| @@ -24,8 +24,18 @@ void showSnackIcon(String text, {IconData icon, Function onAction, bool success, | ||||
|   if (success == true) { | ||||
|     backgroundColor = Colors.lightGreen; | ||||
|  | ||||
|     // Select an icon if we do not have an action | ||||
|     if (icon == null && onAction == null) { | ||||
|       icon = FontAwesomeIcons.checkCircle; | ||||
|     } | ||||
|  | ||||
|   } else if (success == false) { | ||||
|     backgroundColor = Colors.deepOrange; | ||||
|  | ||||
|     if (icon == null && onAction == null) { | ||||
|       icon = FontAwesomeIcons.exclamationCircle; | ||||
|     } | ||||
|  | ||||
|   } | ||||
|  | ||||
|   SnackBarAction action; | ||||
|   | ||||
| @@ -245,6 +245,26 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> { | ||||
|   } | ||||
|  | ||||
|  | ||||
|   void _unassignBarcode(BuildContext context) async { | ||||
|  | ||||
|     final bool result = await item.update(context, values: {'uid': ''}); | ||||
|  | ||||
|     if (result) { | ||||
|       showSnackIcon( | ||||
|         I18N.of(context).stockItemUpdateSuccess, | ||||
|         success: true | ||||
|       ); | ||||
|     } else { | ||||
|       showSnackIcon( | ||||
|         I18N.of(context).stockItemUpdateFailure, | ||||
|         success: false, | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     refresh(); | ||||
|   } | ||||
|  | ||||
|  | ||||
|   void _transferStock(BuildContext context, InvenTreeStockLocation location) async { | ||||
|     Navigator.of(context).pop(); | ||||
|  | ||||
| @@ -568,7 +588,7 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> { | ||||
|     if (item.uid.isEmpty) { | ||||
|       tiles.add( | ||||
|         ListTile( | ||||
|           title: Text(I18N.of(context).assignBarcode), | ||||
|           title: Text(I18N.of(context).barcodeAssign), | ||||
|           leading: FaIcon(FontAwesomeIcons.barcode), | ||||
|           trailing: FaIcon(FontAwesomeIcons.qrcode), | ||||
|           onTap: () { | ||||
| @@ -581,6 +601,16 @@ class _StockItemDisplayState extends RefreshableState<StockDetailWidget> { | ||||
|           } | ||||
|         ) | ||||
|       ); | ||||
|     } else { | ||||
|       tiles.add( | ||||
|         ListTile( | ||||
|           title: Text(I18N.of(context).barcodeUnassign), | ||||
|           leading: FaIcon(FontAwesomeIcons.barcode), | ||||
|           onTap: () { | ||||
|             _unassignBarcode(context); | ||||
|           } | ||||
|         ) | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     return tiles; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user