update stat

This commit is contained in:
JMARyA 2024-09-27 13:15:53 +02:00
parent 167a4620fe
commit d21554cddc
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263

View file

@ -1,4 +1,5 @@
import 'package:cdb_ui/api.dart';
import 'package:cdb_ui/pages/expandable_list.dart';
import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart';
@ -85,16 +86,48 @@ class ItemStatPage extends StatelessWidget {
const ItemStatPage(this.item, {super.key});
// todo : expiry ratio
// todo : avg time of transaction active
ExpandableListItem buildVariantStat(String variant) {
return ExpandableListItem(
body: FutureBuilder(
future: API().getStat(item.id, variant, full: true),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const CircularProgressIndicator();
}
var data = snapshot.data! as FullItemVariantStat;
return Column(
children: [
Text("Amount: ${data.amount}"),
Text("Total Cost: ${data.totalPrice}"),
Text("Expiry Rate: ${data.expiryRate}"),
...data.origins.keys.map((key) {
var originStat = data.origins[key]!;
return Column(children: [
Text("Inventory: ${originStat.inventory}"),
Text(
"Average Price: ${originStat.average_price.toStringAsFixed(2)}"),
]);
}).toList()
],
);
},
),
header: Text(item.variants[variant]!.name));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Statistics of ${item.name}"),
),
body: null,
body: Column(children: [
ExpandableList(item.variants.keys.map(buildVariantStat).toList())
]),
);
}
}