mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-13 18:55:34 +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 {},
|
Map<String, dynamic> modelData = const {},
|
||||||
String method = "PATCH",
|
String method = "PATCH",
|
||||||
Function(Map<String, dynamic>)? onSuccess,
|
Function(Map<String, dynamic>)? onSuccess,
|
||||||
|
bool Function(Map<String, dynamic>)? validate,
|
||||||
Function? onCancel,
|
Function? onCancel,
|
||||||
IconData icon = TablerIcons.device_floppy
|
IconData icon = TablerIcons.device_floppy
|
||||||
}) async {
|
}) async {
|
||||||
@ -1071,6 +1072,7 @@ Future<void> launchApiForm(
|
|||||||
formFields,
|
formFields,
|
||||||
method,
|
method,
|
||||||
onSuccess: onSuccess,
|
onSuccess: onSuccess,
|
||||||
|
validate: validate,
|
||||||
fileField: fileField,
|
fileField: fileField,
|
||||||
icon: icon,
|
icon: icon,
|
||||||
))
|
))
|
||||||
@ -1088,6 +1090,7 @@ class APIFormWidget extends StatefulWidget {
|
|||||||
{
|
{
|
||||||
Key? key,
|
Key? key,
|
||||||
this.onSuccess,
|
this.onSuccess,
|
||||||
|
this.validate,
|
||||||
this.fileField = "",
|
this.fileField = "",
|
||||||
this.icon = TablerIcons.device_floppy,
|
this.icon = TablerIcons.device_floppy,
|
||||||
}
|
}
|
||||||
@ -1111,6 +1114,8 @@ class APIFormWidget extends StatefulWidget {
|
|||||||
|
|
||||||
final Function(Map<String, dynamic>)? onSuccess;
|
final Function(Map<String, dynamic>)? onSuccess;
|
||||||
|
|
||||||
|
final bool Function(Map<String, dynamic>)? validate;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_APIFormWidgetState createState() => _APIFormWidgetState();
|
_APIFormWidgetState createState() => _APIFormWidgetState();
|
||||||
|
|
||||||
@ -1402,6 +1407,12 @@ class _APIFormWidgetState extends State<APIFormWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final bool isValid = widget.validate?.call(data) ?? true;
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Run custom onSuccess function
|
// Run custom onSuccess function
|
||||||
var successFunc = widget.onSuccess;
|
var successFunc = widget.onSuccess;
|
||||||
|
|
||||||
|
@ -623,6 +623,12 @@
|
|||||||
"labelTemplate": "Label Template",
|
"labelTemplate": "Label Template",
|
||||||
"@labelTemplate": {},
|
"@labelTemplate": {},
|
||||||
|
|
||||||
|
"labelSelectTemplate": "Select Label Template",
|
||||||
|
"@labelSelectTemplate": {},
|
||||||
|
|
||||||
|
"labelSelectPrinter": "Select Label Printer",
|
||||||
|
"@labelSelectPrinter": {},
|
||||||
|
|
||||||
"language": "Language",
|
"language": "Language",
|
||||||
"@language": {},
|
"@language": {},
|
||||||
|
|
||||||
|
@ -94,6 +94,28 @@ Future<void> selectAndPrintLabel(
|
|||||||
"",
|
"",
|
||||||
fields,
|
fields,
|
||||||
icon: TablerIcons.printer,
|
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 {
|
onSuccess: (Map<String, dynamic> data) async {
|
||||||
int labelId = (data["label"] ?? -1) as int;
|
int labelId = (data["label"] ?? -1) as int;
|
||||||
var pluginKey = data["plugin"];
|
var pluginKey = data["plugin"];
|
||||||
|
Reference in New Issue
Block a user