add stat
This commit is contained in:
parent
86fb3d6370
commit
bb4fab6a11
3 changed files with 41 additions and 3 deletions
15
lib/api.dart
15
lib/api.dart
|
@ -102,6 +102,11 @@ class API {
|
|||
{"uuid": transaction, "destination": destination, "price": price});
|
||||
}
|
||||
|
||||
Future<ItemVariantStat> 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<String, dynamic> json) {
|
||||
amount = json["amount"];
|
||||
total_price = json["total_price"];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -34,7 +34,7 @@ class _ItemViewState extends State<ItemView> {
|
|||
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<ItemView> {
|
|||
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),
|
||||
|
|
Loading…
Reference in a new issue