cdb_ui/lib/pages/home.dart
JMARyA 619f7b804a
All checks were successful
ci/woodpecker/push/build Pipeline was successful
remove stats
2024-12-15 03:59:32 +01:00

95 lines
2.9 KiB
Dart

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';
class HomePage extends StatelessWidget {
const HomePage({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
// global origin / destinations
return Scaffold(
appBar: AppBar(
title: const Text("Home"),
),
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(
margin: const EdgeInsets.all(10.0),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconText(Icons.data_object,
"Items: ${globalStat.itemCount}"),
IconText(Icons.list_alt,
"Inventory: ${globalStat.totalTransactions}"),
IconText(Icons.money,
"Price: ${globalStat.totalPrice.toStringAsFixed(2)}")
],
),
)),
if (min.isNotEmpty)
const ListTile(
title: Text(
"Items under Minimum",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
)),
...min.map((item) {
var (itemID, variant) = itemVariant(item.itemVariant);
var name = API().getItem(itemID).variants[variant]!.name;
return ListTile(
title: Text("$name under minimum. Needs ${item.need} more."),
);
}).toList(),
if (expired.isNotEmpty)
const ListTile(
title: Text(
"Expired Items",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
)),
// Mapping expired list to widgets
...expired.map((item) {
return ListTile(
title: TransactionCard(item, () {}),
);
}).toList(),
],
);
},
),
);
}
}