2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-27 21:16:48 +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()); }
// 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) {
filters = {};
@ -62,24 +62,27 @@ class InvenTreeObject {
// TODO - Add "timeout"
// TODO - Add error catching
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);
for (var d in data) {
print(d);
var obj = _createFromJson(d);
// Create a new object (of the current class type
InvenTreeObject obj = _createFromJson(d);
if (obj is InvenTreePart) {
print("Part -> " + obj.name + obj.description);
} else {
print("Not part :'(");
print(obj.runtimeType);
if (obj != null) {
results.add(obj);
}
}
// var obj = _createFromJson(data);
return results;
});
}