2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 13:36:50 +00:00

Add callback functions

This commit is contained in:
Oliver 2021-07-16 17:35:56 +10:00
parent faf20030e3
commit 27caf3983a
2 changed files with 12 additions and 2 deletions

View File

@ -137,7 +137,7 @@ Map<String, dynamic> extractFields(APIResponse response) {
* @param method is the HTTP method to use to send the form data to the server (e.g. POST / PATCH)
*/
Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields, {Map<String, dynamic> modelData = const {}, String method = "PATCH"}) async {
Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields, {Map<String, dynamic> modelData = const {}, String method = "PATCH", Function? onSuccess, Function? onCancel}) async {
var options = await InvenTreeAPI().options(url);
@ -225,6 +225,11 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
case 201:
// Form was validated by the server
Navigator.pop(context);
if (onSuccess != null) {
onSuccess();
}
break;
case 400:
@ -255,6 +260,10 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
child: Text(L10().cancel),
onPressed: () {
Navigator.pop(context);
if (onCancel != null) {
onCancel();
}
},
),
// Save button

View File

@ -192,7 +192,8 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
},
"active": {},
},
modelData: part.jsondata
modelData: part.jsondata,
onSuccess: refresh,
);
return;