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

Reload model data from server

This commit is contained in:
Oliver Walters 2020-04-09 23:21:35 +10:00
parent 4cafa668a5
commit f158b0cd12

View File

@ -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<String, String> defaultGetFilters() { return Map<String, String>(); }
/*
* 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<String, dynamic> data = json.decode(response.body);
jsondata = data;
}
// Return the detail view for the associated pk
Future<InvenTreeModel> get(int pk, {Map<String, String> filters}) async {