diff --git a/lib/api.dart b/lib/api.dart index a3adacf..7a76f9c 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -47,8 +47,20 @@ class API { jsonDecode(await getRequest("$instance/transaction/$id"))); } - Future>> getInventory(String item) async { - return jsonDecode(await getRequest("$instance/item/$item/inventory")); + Future> getInventory(String item) async { + var resp = jsonDecode(await getRequest("$instance/item/$item/inventory")) + as List; + + return resp.map((x) => Transaction(x)).toList(); + } + + Future> getInventoryOfVariant( + String item, String variant) async { + var resp = + jsonDecode(await getRequest("$instance/item/$item/$variant/inventory")) + as List; + + return resp.map((x) => Transaction(x)).toList(); } Future supplyItem(String item, String variant, String price, diff --git a/lib/itemview.dart b/lib/itemview.dart index 7dda510..852b1c0 100644 --- a/lib/itemview.dart +++ b/lib/itemview.dart @@ -26,26 +26,21 @@ class ItemView extends StatelessWidget { ], ), const SizedBox(height: 10), + Row( + children: item.variants.entries.map((entry) { + return Text(entry.value.name); + }).toList()), FutureBuilder( future: API().getInventory(item.id), builder: (context, snapshot) { - if (snapshot.hasData) { - var data = snapshot.data!; - - return Column( - children: data.map((x) { - return Row( - children: [ - Text(x["uuid"]), - Text(x["origin"]), - Text(x["price"]), - Text(x["timestamp"]) - ], - ); - }).toList()); + if (!snapshot.hasData) { + return const CircularProgressIndicator(); } + var data = snapshot.data!; - return const CircularProgressIndicator(); + return Expanded( + child: ListView( + children: data.map((x) => TransactionCard(x)).toList())); }, ) ]), @@ -61,6 +56,25 @@ class ItemView extends StatelessWidget { const ItemView({super.key, required this.item}); } +class TransactionCard extends StatelessWidget { + final Transaction t; + + const TransactionCard(this.t, {super.key}); + + @override + Widget build(BuildContext context) { + return Card( + child: Column( + children: [ + Row( + children: [Text(t.uuid), Text(t.item), Text(t.variant)], + ), + ], + ), + ); + } +} + class SupplyPage extends StatefulWidget { final Item item;