diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 50ccadb5..450a20cf 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'model.dart'; import 'package:InvenTree/api.dart'; @@ -23,9 +25,50 @@ class InvenTreeStockItem extends InvenTreeModel { // TODO } - String get partName => jsondata['part__name'] as String ?? ''; + String get partName { - String get partDescription => jsondata['part__description'] as String ?? ''; + String nm = ''; + + // Use the detailed part information as priority + if (jsondata.containsKey('part_detail')) { + nm = jsondata['part_detail']['full_name'] ?? ''; + } + + if (nm.isEmpty) { + nm = jsondata['part__name'] ?? ''; + } + + return nm; + } + + String get partDescription { + String desc = ''; + + // Use the detailed part description as priority + if (jsondata.containsKey('part_detail')) { + desc = jsondata['part_detail']['description'] ?? ''; + } + + if (desc.isEmpty) { + desc = jsondata['part__description'] ?? ''; + } + + return desc; + } + + String get partImage { + String img = ''; + + if (jsondata.containsKey('part_detail')) { + img = jsondata['part_detail']['thumbnail'] ?? ''; + } + + if (img.isEmpty) { + img = jsondata['part__thumbnail'] ?? ''; + } + + return img; + } String get partThumbnail { String thumb = jsondata['part__thumbnail'] as String ?? ''; diff --git a/lib/widget/stock_display.dart b/lib/widget/stock_display.dart index a4e04a97..5bce2bde 100644 --- a/lib/widget/stock_display.dart +++ b/lib/widget/stock_display.dart @@ -4,7 +4,10 @@ import 'package:InvenTree/inventree/stock.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:InvenTree/api.dart'; + import 'package:InvenTree/widget/drawer.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class StockItemDisplayWidget extends StatefulWidget { @@ -25,14 +28,6 @@ class _StockItemDisplayState extends State { final InvenTreeStockItem item; - String get _title { - if (item == null) { - return "Stock Item"; - } else { - return "Item: x ${item.partName}"; - } - } - /* * Construct a list of detail elements about this StockItem. * The number of elements may vary depending on the StockItem details @@ -45,6 +40,14 @@ class _StockItemDisplayState extends State { Card( child: ListTile( title: Text("${item.partName}"), + subtitle: Text("${item.partDescription}"), + leading: Image( + image: InvenTreeAPI().getImage(item.partImage), + ), + trailing: IconButton( + icon: FaIcon(FontAwesomeIcons.edit), + onPressed: null, + ) ) ) ); @@ -56,15 +59,12 @@ class _StockItemDisplayState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text(_title), + title: Text("Stock Item"), ), drawer: new InvenTreeDrawer(context), body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("Stock Item: hello"), - ], + child: ListView( + children: stockTiles(), ) ) );