diff --git a/lib/api.dart b/lib/api.dart index 1c403aa..52c0086 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -102,6 +102,11 @@ class API { {"uuid": transaction, "destination": destination, "price": price}); } + Future getStat(String item, String variant) async { + return ItemVariantStat( + jsonDecode(await getRequest("$instance/item/$item/$variant/stat"))); + } + String getImageURL(String item) { return "$instance/$item/image"; } @@ -184,3 +189,13 @@ class ConsumeInfo { timestamp = json["timestamp"]; } } + +class ItemVariantStat { + late int amount; + late double total_price; + + ItemVariantStat(Map json) { + amount = json["amount"]; + total_price = json["total_price"]; + } +} diff --git a/lib/main.dart b/lib/main.dart index ab8dc0b..95f06d5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,7 +15,8 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'CDB', theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + colorScheme: ColorScheme.fromSeed( + seedColor: Colors.deepPurple, brightness: Brightness.dark), useMaterial3: true, ), home: const MyHomePage(), diff --git a/lib/pages/itemview.dart b/lib/pages/itemview.dart index bcf39bf..72029d2 100644 --- a/lib/pages/itemview.dart +++ b/lib/pages/itemview.dart @@ -34,7 +34,7 @@ class _ItemViewState extends State { widget.item.name, style: const TextStyle(fontWeight: FontWeight.bold), ), - Text(widget.item.category) + Text(widget.item.category), ], ) ], @@ -42,7 +42,29 @@ class _ItemViewState extends State { const SizedBox(height: 10), Row( children: widget.item.variants.entries.map((entry) { - return Text(entry.value.name); + return Column(children: [ + Text( + entry.value.name, + style: TextStyle(fontWeight: FontWeight.bold), + ), + FutureBuilder( + future: API().getStat(widget.item.id, entry.key), + builder: (context, snapshot) { + if (!snapshot.hasData) { + return CircularProgressIndicator(); + } + + var stat = snapshot.data!; + + return Column( + children: [ + Text("Amount: ${stat.amount}"), + Text("Total Cost: ${stat.total_price}") + ], + ); + }, + ) + ]); }).toList()), FutureBuilder( future: API().getInventory(widget.item.id),