From 3a686b8b7f30884570b45d43b023452e999bb110 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 3 Apr 2020 12:23:57 +1100 Subject: [PATCH] Display for StockItem - Empty for now --- lib/widget/category_display.dart | 6 +-- lib/widget/location_display.dart | 91 ++++++++++++++++++++++++++++++-- lib/widget/stock_display.dart | 51 ++++++++++++++++++ 3 files changed, 138 insertions(+), 10 deletions(-) create mode 100644 lib/widget/stock_display.dart diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 913bdd5b..dcf01ac2 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -126,11 +126,7 @@ class SubcategoryList extends StatelessWidget { } Widget _build(BuildContext context, int index) { - InvenTreePartCategory cat; - - if (index < _categories.length) { - cat = _categories[index]; - } + InvenTreePartCategory cat = _categories[index]; return Card( child: InkWell( diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index 49bdba44..dd549667 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -1,7 +1,9 @@ import 'package:InvenTree/inventree/stock.dart'; +import 'package:InvenTree/widget/stock_display.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart'; class LocationDisplayWidget extends StatefulWidget { @@ -29,8 +31,12 @@ class _LocationDisplayState extends State { List _items = List(); String get _title { - // TODO - return "Location:"; + + if (location == null) { + return "Location:"; + } else { + return "Stock Location '${location.name}'"; + } } void _requestData() { @@ -63,8 +69,6 @@ class _LocationDisplayState extends State { }); }); - - // TODO } @override @@ -82,15 +86,92 @@ class _LocationDisplayState extends State { textAlign: TextAlign.left, style: TextStyle(fontWeight: FontWeight.bold), ), + Expanded(child: SublocationList(_sublocations)), Divider(), Text( "Stock Items - ${_items.length}", textAlign: TextAlign.left, style: TextStyle(fontWeight: FontWeight.bold), - ) + ), + Expanded(child: StockList(_items)), ], ) ), ); } +} + + +class SublocationList extends StatelessWidget { + final List _locations; + + SublocationList(this._locations); + + void _openLocation(BuildContext context, int pk) { + + InvenTreeStockLocation().get(pk).then((var loc) { + if (loc is InvenTreeStockLocation) { + + Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(loc))); + } + }); + } + + Widget _build(BuildContext context, int index) { + InvenTreeStockLocation loc = _locations[index]; + + return Card( + child: InkWell( + child: Column( + children: [ + Text('${loc.name} - ${loc.description}'), + ], + ), + onTap: () { + _openLocation(context, loc.pk); + }, + ) + ); + } + + @override + Widget build(BuildContext context) { + return ListView.builder(itemBuilder: _build, itemCount: _locations.length); + } +} + +class StockList extends StatelessWidget { + final List _items; + + StockList(this._items); + + void _openItem(BuildContext context, int pk) { + InvenTreeStockItem().get(pk).then((var item) { + if (item is InvenTreeStockItem) { + Navigator.push(context, MaterialPageRoute(builder: (context) => StockItemDisplayWidget(item))); + } + }); + } + + Widget _build(BuildContext context, int index) { + InvenTreeStockItem item = _items[index]; + + return Card( + child: InkWell( + child: Column( + children: [ + Text('${item.quantity.toString()} x ${item.partName}') + ] + ), + onTap: () { + _openItem(context, item.pk); + }, + ) + ); + } + + @override + Widget build(BuildContext context) { + return ListView.builder(itemBuilder: _build, itemCount: _items.length); + } } \ No newline at end of file diff --git a/lib/widget/stock_display.dart b/lib/widget/stock_display.dart new file mode 100644 index 00000000..dc62faa5 --- /dev/null +++ b/lib/widget/stock_display.dart @@ -0,0 +1,51 @@ + + +import 'package:InvenTree/inventree/stock.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +class StockItemDisplayWidget extends StatefulWidget { + + StockItemDisplayWidget(this.item, {Key key}) : super(key: key); + + final InvenTreeStockItem item; + + @override + _StockItemDisplayState createState() => _StockItemDisplayState(item); +} + + +class _StockItemDisplayState extends State { + + _StockItemDisplayState(this.item) { + // TODO + } + + final InvenTreeStockItem item; + + String get _title { + if (item == null) { + return "Stock Item"; + } else { + print(item.jsondata); + return "Item: x ${item.partName}"; + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(_title), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("Stock Item: hello"), + ], + ) + ) + ); + } +} \ No newline at end of file