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});
|
{"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) {
|
String getImageURL(String item) {
|
||||||
return "$instance/$item/image";
|
return "$instance/$item/image";
|
||||||
}
|
}
|
||||||
|
@ -184,3 +189,13 @@ class ConsumeInfo {
|
||||||
timestamp = json["timestamp"];
|
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(
|
return MaterialApp(
|
||||||
title: 'CDB',
|
title: 'CDB',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
colorScheme: ColorScheme.fromSeed(
|
||||||
|
seedColor: Colors.deepPurple, brightness: Brightness.dark),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
home: const MyHomePage(),
|
home: const MyHomePage(),
|
||||||
|
|
|
@ -34,7 +34,7 @@ class _ItemViewState extends State<ItemView> {
|
||||||
widget.item.name,
|
widget.item.name,
|
||||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
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),
|
const SizedBox(height: 10),
|
||||||
Row(
|
Row(
|
||||||
children: widget.item.variants.entries.map((entry) {
|
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()),
|
}).toList()),
|
||||||
FutureBuilder(
|
FutureBuilder(
|
||||||
future: API().getInventory(widget.item.id),
|
future: API().getInventory(widget.item.id),
|
||||||
|
|
Loading…
Reference in a new issue