From f158b0cd121ff6dad8eb9797ee8c6ae2781bfda8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 9 Apr 2020 23:21:35 +1000 Subject: [PATCH] Reload model data from server --- lib/inventree/model.dart | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index d929df88..a0e2c639 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -56,7 +56,8 @@ class InvenTreeModel { return obj; } - String get url{ return path.join(URL, pk.toString()); } + // Return the API detail endpoint for this Model object + String get url => "${URL}/${pk}/"; /* // Search this Model type in the database @@ -79,6 +80,25 @@ class InvenTreeModel { // A map of "default" headers to use when performing a GET request Map defaultGetFilters() { return Map(); } + /* + * Reload this object, by requesting data from the server + */ + void reload() async { + + print("Reloading data from $url"); + + var response = await api.get(url); + + if (response.statusCode != 200) { + print("Error retrieving data"); + return; + } + + final Map data = json.decode(response.body); + + jsondata = data; + } + // Return the detail view for the associated pk Future get(int pk, {Map filters}) async {