From 7d060acc932d05c79665449ff750af609b5c97a4 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Fri, 3 Apr 2020 11:28:46 +1100
Subject: [PATCH] Add "location" display widget

---
 lib/widget/category_display.dart |  1 -
 lib/widget/location_display.dart | 96 ++++++++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)
 create mode 100644 lib/widget/location_display.dart

diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart
index 28479dd5..913bdd5b 100644
--- a/lib/widget/category_display.dart
+++ b/lib/widget/category_display.dart
@@ -98,7 +98,6 @@ class _CategoryDisplayState extends State<CategoryDisplayWidget> {
               style: TextStyle(fontWeight: FontWeight.bold),
             ),
             Expanded(child: PartList(_parts)),
-            Spacer(),
           ]
         )
       )
diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart
new file mode 100644
index 00000000..49bdba44
--- /dev/null
+++ b/lib/widget/location_display.dart
@@ -0,0 +1,96 @@
+
+import 'package:InvenTree/inventree/stock.dart';
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+
+class LocationDisplayWidget extends StatefulWidget {
+
+  LocationDisplayWidget(this.location, {Key key}) : super(key: key);
+
+  final InvenTreeStockLocation location;
+
+  final String title = "Location";
+
+  @override
+  _LocationDisplayState createState() => _LocationDisplayState(location);
+}
+
+
+class _LocationDisplayState extends State<LocationDisplayWidget> {
+
+  _LocationDisplayState(this.location) {
+    _requestData();
+  }
+
+  final InvenTreeStockLocation location;
+
+  List<InvenTreeStockLocation> _sublocations = List<InvenTreeStockLocation>();
+
+  List<InvenTreeStockItem> _items = List<InvenTreeStockItem>();
+
+  String get _title {
+    // TODO
+    return "Location:";
+  }
+
+  void _requestData() {
+
+    int pk = location?.pk ?? -1;
+
+    // Request a list of sub-locations under this one
+    InvenTreeStockLocation().list(filters: {"parent": "$pk"}).then((var locs) {
+      _sublocations.clear();
+
+      for (var loc in locs) {
+        if (loc is InvenTreeStockLocation) {
+          _sublocations.add(loc);
+        }
+      }
+
+      setState(() {});
+
+    // Request a list of stock-items under this one
+    InvenTreeStockItem().list(filters: {"location": "$pk"}).then((var items) {
+      _items.clear();
+
+      for (var item in items) {
+        if (item is InvenTreeStockItem) {
+          _items.add(item);
+        }
+      }
+
+      setState(() {});
+    });
+
+    });
+
+    // TODO
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      appBar: AppBar(
+        title: Text(_title),
+      ),
+      body: Center(
+        child: Column(
+          mainAxisAlignment: MainAxisAlignment.center,
+          children: <Widget>[
+            Text(
+              "Sublocations - ${_sublocations.length}",
+              textAlign: TextAlign.left,
+              style: TextStyle(fontWeight: FontWeight.bold),
+            ),
+            Divider(),
+            Text(
+              "Stock Items - ${_items.length}",
+              textAlign: TextAlign.left,
+              style: TextStyle(fontWeight: FontWeight.bold),
+            )
+          ],
+        )
+      ),
+    );
+  }
+}
\ No newline at end of file