From 27caf3983aa88fd5a122b1b5a983845d770c380d Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 16 Jul 2021 17:35:56 +1000 Subject: [PATCH] Add callback functions --- lib/api_form.dart | 11 ++++++++++- lib/widget/part_detail.dart | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/api_form.dart b/lib/api_form.dart index 11c764a6..24b4b351 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -137,7 +137,7 @@ Map extractFields(APIResponse response) { * @param method is the HTTP method to use to send the form data to the server (e.g. POST / PATCH) */ -Future launchApiForm(String title, String url, Map fields, {Map modelData = const {}, String method = "PATCH"}) async { +Future launchApiForm(String title, String url, Map fields, {Map modelData = const {}, String method = "PATCH", Function? onSuccess, Function? onCancel}) async { var options = await InvenTreeAPI().options(url); @@ -225,6 +225,11 @@ Future launchApiForm(String title, String url, Map fields case 201: // Form was validated by the server Navigator.pop(context); + + if (onSuccess != null) { + onSuccess(); + } + break; case 400: @@ -255,6 +260,10 @@ Future launchApiForm(String title, String url, Map fields child: Text(L10().cancel), onPressed: () { Navigator.pop(context); + + if (onCancel != null) { + onCancel(); + } }, ), // Save button diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 88bd0b3c..2f058d9a 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -192,7 +192,8 @@ class _PartDisplayState extends RefreshableState { }, "active": {}, }, - modelData: part.jsondata + modelData: part.jsondata, + onSuccess: refresh, ); return;