2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 21:46:46 +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) * @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); var options = await InvenTreeAPI().options(url);
@ -225,6 +225,11 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
case 201: case 201:
// Form was validated by the server // Form was validated by the server
Navigator.pop(context); Navigator.pop(context);
if (onSuccess != null) {
onSuccess();
}
break; break;
case 400: case 400:
@ -255,6 +260,10 @@ Future<void> launchApiForm(String title, String url, Map<String, dynamic> fields
child: Text(L10().cancel), child: Text(L10().cancel),
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
if (onCancel != null) {
onCancel();
}
}, },
), ),
// Save button // Save button

View File

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