73 lines
2 KiB
Dart
73 lines
2 KiB
Dart
|
import 'package:cdb_ui/api.dart';
|
||
|
import 'package:cdb_ui/pages/itemview.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
|
||
|
class StatsPage extends StatelessWidget {
|
||
|
const StatsPage({super.key});
|
||
|
|
||
|
Future<(List<MinItem>, List<Transaction>, GlobalItemStat)>
|
||
|
_fetchData() async {
|
||
|
return (
|
||
|
await API().getItemsUnderMin(),
|
||
|
await API().getExpiredItems(),
|
||
|
await API().getGlobalItemStat()
|
||
|
);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
// todo : add global statistics
|
||
|
// todo : demand stat
|
||
|
// todo : stat on origin + destination
|
||
|
// todo : add btn for scanning transaction
|
||
|
|
||
|
return Scaffold(
|
||
|
body: FutureBuilder(
|
||
|
future: _fetchData(),
|
||
|
builder: (context, snapshot) {
|
||
|
if (!snapshot.hasData) {
|
||
|
return const CircularProgressIndicator();
|
||
|
}
|
||
|
|
||
|
var data = snapshot.data!;
|
||
|
var min = data.$1;
|
||
|
var expired = data.$2;
|
||
|
var globalStat = data.$3;
|
||
|
|
||
|
return Column(
|
||
|
children: [
|
||
|
Card(
|
||
|
child: Column(
|
||
|
children: [
|
||
|
Text("Items: ${globalStat.item_count}"),
|
||
|
Text("Inventory: ${globalStat.total_transactions}"),
|
||
|
Text("Price: ${globalStat.total_price} €")
|
||
|
],
|
||
|
)),
|
||
|
|
||
|
if (min.isNotEmpty)
|
||
|
const ListTile(title: Text("Items under Minimum")),
|
||
|
...min.map((item) {
|
||
|
return ListTile(
|
||
|
title: Text(
|
||
|
"Item ${item.itemVariant} under minimum. Needs ${item.need} more."),
|
||
|
);
|
||
|
}).toList(),
|
||
|
|
||
|
if (expired.isNotEmpty)
|
||
|
const ListTile(title: Text("Expired Items")),
|
||
|
|
||
|
// Mapping expired list to widgets
|
||
|
...expired.map((item) {
|
||
|
return ListTile(
|
||
|
title: TransactionCard(item, () {}),
|
||
|
);
|
||
|
}).toList(),
|
||
|
],
|
||
|
);
|
||
|
},
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|