mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-31 13:25:40 +00:00 
			
		
		
		
	Improve error management for label printing (#588)
- Handle empty label - Handle empty printer
This commit is contained in:
		| @@ -982,6 +982,7 @@ Future<void> launchApiForm( | ||||
|       Map<String, dynamic> modelData = const {}, | ||||
|       String method = "PATCH", | ||||
|       Function(Map<String, dynamic>)? onSuccess, | ||||
|       bool Function(Map<String, dynamic>)? validate, | ||||
|       Function? onCancel, | ||||
|       IconData icon = TablerIcons.device_floppy | ||||
|     }) async { | ||||
| @@ -1071,6 +1072,7 @@ Future<void> launchApiForm( | ||||
|       formFields, | ||||
|       method, | ||||
|       onSuccess: onSuccess, | ||||
|       validate: validate, | ||||
|       fileField: fileField, | ||||
|       icon: icon, | ||||
|     )) | ||||
| @@ -1088,6 +1090,7 @@ class APIFormWidget extends StatefulWidget { | ||||
|       { | ||||
|         Key? key, | ||||
|         this.onSuccess, | ||||
|         this.validate, | ||||
|         this.fileField = "", | ||||
|         this.icon = TablerIcons.device_floppy, | ||||
|       } | ||||
| @@ -1111,6 +1114,8 @@ class APIFormWidget extends StatefulWidget { | ||||
|  | ||||
|   final Function(Map<String, dynamic>)? onSuccess; | ||||
|  | ||||
|   final bool Function(Map<String, dynamic>)? validate; | ||||
|  | ||||
|   @override | ||||
|   _APIFormWidgetState createState() => _APIFormWidgetState(); | ||||
|  | ||||
| @@ -1401,6 +1406,12 @@ class _APIFormWidgetState extends State<APIFormWidget> { | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|      | ||||
|     final bool isValid = widget.validate?.call(data) ?? true; | ||||
|  | ||||
|     if (!isValid) { | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     // Run custom onSuccess function | ||||
|     var successFunc = widget.onSuccess; | ||||
|   | ||||
| @@ -623,6 +623,12 @@ | ||||
|   "labelTemplate": "Label Template", | ||||
|   "@labelTemplate": {}, | ||||
|  | ||||
|   "labelSelectTemplate": "Select Label Template", | ||||
|   "@labelSelectTemplate": {}, | ||||
|  | ||||
|   "labelSelectPrinter": "Select Label Printer", | ||||
|   "@labelSelectPrinter": {}, | ||||
|  | ||||
|   "language": "Language", | ||||
|   "@language": {}, | ||||
|  | ||||
|   | ||||
| @@ -94,6 +94,28 @@ Future<void> selectAndPrintLabel( | ||||
|     "", | ||||
|     fields, | ||||
|     icon: TablerIcons.printer, | ||||
|     validate: (Map<String, dynamic> data) { | ||||
|       final template = data["label"]; | ||||
|       final plugin = data["plugin"]; | ||||
|  | ||||
|       if (template == null) { | ||||
|         showSnackIcon( | ||||
|           L10().labelSelectTemplate, | ||||
|           success: false, | ||||
|         ); | ||||
|         return false; | ||||
|       } | ||||
|  | ||||
|       if (plugin == null) { | ||||
|         showSnackIcon( | ||||
|           L10().labelSelectPrinter, | ||||
|           success: false, | ||||
|         ); | ||||
|         return false; | ||||
|       } | ||||
|  | ||||
|       return true; | ||||
|     }, | ||||
|     onSuccess: (Map<String, dynamic> data) async { | ||||
|       int labelId = (data["label"] ?? -1) as int; | ||||
|       var pluginKey = data["plugin"]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user