2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-11 17:55:28 +00:00

Improve error management for label printing (#588)

- Handle empty label
- Handle empty printer
This commit is contained in:
Oliver
2024-12-23 10:36:36 +11:00
committed by GitHub
parent bc44b99d43
commit d84f76d482
3 changed files with 39 additions and 0 deletions

View File

@ -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;

View File

@ -623,6 +623,12 @@
"labelTemplate": "Label Template",
"@labelTemplate": {},
"labelSelectTemplate": "Select Label Template",
"@labelSelectTemplate": {},
"labelSelectPrinter": "Select Label Printer",
"@labelSelectPrinter": {},
"language": "Language",
"@language": {},

View File

@ -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"];