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

Cleanup of list creation

This commit is contained in:
Oliver Walters 2020-03-31 23:03:05 +11:00
parent ef09b024e6
commit e75297053b

View File

@ -51,7 +51,7 @@ class InvenTreeObject {
String get url{ return path.join(_URL, pk.toString()); } String get url{ return path.join(_URL, pk.toString()); }
// Return list of objects from the database, with optional filters // Return list of objects from the database, with optional filters
Future<http.Response> list({Map<String, String> filters}) async { Future<List<InvenTreeObject>> list({Map<String, String> filters}) async {
if (filters == null) { if (filters == null) {
filters = {}; filters = {};
@ -62,24 +62,27 @@ class InvenTreeObject {
// TODO - Add "timeout" // TODO - Add "timeout"
// TODO - Add error catching // TODO - Add error catching
InvenTreeAPI().get(_URL, params:filters).then((http.Response response) { InvenTreeAPI().get(_URL, params:filters).then((http.Response response) {
// A list of "InvenTreeObject" items
List<InvenTreeObject> results = new List<InvenTreeObject>();
final data = json.decode(response.body); final data = json.decode(response.body);
for (var d in data) { for (var d in data) {
print(d); print(d);
var obj = _createFromJson(d); // Create a new object (of the current class type
InvenTreeObject obj = _createFromJson(d);
if (obj is InvenTreePart) { if (obj != null) {
print("Part -> " + obj.name + obj.description); results.add(obj);
} else {
print("Not part :'(");
print(obj.runtimeType);
} }
} }
// var obj = _createFromJson(data);
return results;
}); });
} }