diff --git a/lib/pages/stats.dart b/lib/pages/stats.dart index b612280..e50b52e 100644 --- a/lib/pages/stats.dart +++ b/lib/pages/stats.dart @@ -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()) + ]), ); } }