cdb_ui/lib/pages/home.dart

96 lines
2.9 KiB
Dart
Raw Permalink Normal View History

2024-09-20 07:18:06 +00:00
import 'package:cdb_ui/api.dart';
2024-09-27 11:15:53 +00:00
import 'package:cdb_ui/pages/expandable_list.dart';
2024-09-21 15:15:12 +00:00
import 'package:cdb_ui/pages/transaction.dart';
2024-09-20 07:18:06 +00:00
import 'package:flutter/material.dart';
2024-12-15 02:59:32 +00:00
class HomePage extends StatelessWidget {
const HomePage({super.key});
2024-09-20 07:18:06 +00:00
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
2024-09-26 13:44:04 +00:00
// global origin / destinations
2024-09-20 07:18:06 +00:00
return Scaffold(
2024-10-08 08:55:30 +00:00
appBar: AppBar(
title: const Text("Home"),
),
2024-09-20 07:18:06 +00:00
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(
2024-09-26 13:44:04 +00:00
margin: const EdgeInsets.all(10.0),
2024-09-21 15:15:12 +00:00
child: Padding(
2024-09-26 13:44:04 +00:00
padding: const EdgeInsets.all(10.0),
2024-09-21 15:15:12 +00:00
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconText(Icons.data_object,
2024-10-08 08:55:30 +00:00
"Items: ${globalStat.itemCount}"),
2024-09-21 15:15:12 +00:00
IconText(Icons.list_alt,
2024-10-08 08:55:30 +00:00
"Inventory: ${globalStat.totalTransactions}"),
2024-09-21 15:15:12 +00:00
IconText(Icons.money,
2024-10-08 08:55:30 +00:00
"Price: ${globalStat.totalPrice.toStringAsFixed(2)}")
2024-09-21 15:15:12 +00:00
],
),
)),
2024-09-20 07:18:06 +00:00
if (min.isNotEmpty)
2024-10-08 11:47:17 +00:00
const ListTile(
title: Text(
"Items under Minimum",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
)),
2024-09-20 07:18:06 +00:00
...min.map((item) {
2024-10-08 11:47:17 +00:00
var (itemID, variant) = itemVariant(item.itemVariant);
var name = API().getItem(itemID).variants[variant]!.name;
2024-09-20 07:18:06 +00:00
return ListTile(
2024-10-08 11:47:17 +00:00
title: Text("$name under minimum. Needs ${item.need} more."),
2024-09-20 07:18:06 +00:00
);
}).toList(),
if (expired.isNotEmpty)
2024-10-08 11:47:17 +00:00
const ListTile(
title: Text(
"Expired Items",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
)),
2024-09-20 07:18:06 +00:00
// Mapping expired list to widgets
...expired.map((item) {
return ListTile(
title: TransactionCard(item, () {}),
);
}).toList(),
],
);
},
),
);
}
}