cdb_ui/lib/pages/itemview.dart

130 lines
4.1 KiB
Dart
Raw Normal View History

2024-09-07 21:56:52 +00:00
import 'package:cdb_ui/api.dart';
2024-09-26 13:44:04 +00:00
import 'package:cdb_ui/pages/stats.dart';
2024-09-21 15:15:12 +00:00
import 'package:cdb_ui/pages/transaction.dart';
2024-09-07 21:56:52 +00:00
import 'package:flutter/material.dart';
import 'supply.dart';
2024-09-22 20:15:43 +00:00
// todo : show est. time remaining until inventory gets empty (based on demand)
2024-09-07 22:24:13 +00:00
class ItemView extends StatefulWidget {
2024-09-07 21:56:52 +00:00
final Item item;
2024-09-07 22:24:13 +00:00
@override
State<ItemView> createState() => _ItemViewState();
const ItemView({super.key, required this.item});
}
class _ItemViewState extends State<ItemView> {
void refresh() {
setState(() {});
}
2024-09-07 21:56:52 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
2024-09-08 15:45:48 +00:00
appBar: AppBar(
title: Text(widget.item.name),
2024-09-26 13:44:04 +00:00
actions: [
IconButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => ItemStatPage(widget.item),
));
},
2024-10-08 08:55:30 +00:00
icon: const Icon(Icons.bar_chart))
2024-09-26 13:44:04 +00:00
],
2024-09-08 15:45:48 +00:00
),
2024-09-07 21:56:52 +00:00
body: Column(children: [
2024-09-15 15:43:32 +00:00
Padding(
2024-09-15 15:49:50 +00:00
padding: const EdgeInsets.symmetric(horizontal: 28),
2024-09-15 15:43:32 +00:00
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
2024-10-18 09:02:28 +00:00
Align(
2024-09-15 15:43:32 +00:00
alignment: Alignment.centerLeft,
2024-10-18 09:02:28 +00:00
child: widget.item.image != null
? Image.network(
"${API().instance}/${widget.item.image}",
height: 100,
width: 100,
)
: null,
2024-09-25 08:49:21 +00:00
),
2024-09-15 15:49:50 +00:00
const SizedBox(
2024-09-15 15:43:32 +00:00
width: 16.0,
),
Column(
children: [
Text(
widget.item.name,
style: const TextStyle(fontWeight: FontWeight.bold),
),
2024-09-23 18:19:30 +00:00
if (widget.item.category != null)
Text(widget.item.category!),
2024-09-15 15:43:32 +00:00
],
)
],
2024-09-15 13:15:46 +00:00
),
2024-09-15 15:43:32 +00:00
const SizedBox(height: 18),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: widget.item.variants.entries.map((entry) {
return Column(children: [
Text(
entry.value.name,
2024-09-15 15:49:50 +00:00
style: const TextStyle(fontWeight: FontWeight.bold),
2024-09-15 15:43:32 +00:00
),
FutureBuilder(
future: API().getStat(widget.item.id, entry.key),
builder: (context, snapshot) {
if (!snapshot.hasData) {
2024-09-15 15:49:50 +00:00
return const CircularProgressIndicator();
2024-09-15 15:43:32 +00:00
}
2024-09-07 22:51:18 +00:00
2024-09-15 15:43:32 +00:00
var stat = snapshot.data!;
2024-09-07 22:51:18 +00:00
2024-09-15 15:43:32 +00:00
return Column(
children: [
Text("Amount: ${stat.amount}"),
Text(
2024-09-16 07:42:55 +00:00
"Total Cost: ${stat.totalPrice.toStringAsFixed(2)}")
2024-09-15 15:43:32 +00:00
],
);
},
)
]);
}).toList()),
2024-09-15 15:49:50 +00:00
const SizedBox(
2024-09-15 15:43:32 +00:00
height: 12,
)
],
),
),
2024-09-07 21:56:52 +00:00
FutureBuilder(
2024-09-07 22:24:13 +00:00
future: API().getInventory(widget.item.id),
2024-09-07 21:56:52 +00:00
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const CircularProgressIndicator();
}
var data = snapshot.data!;
return Expanded(
child: ListView(
2024-09-07 22:24:13 +00:00
children:
data.map((x) => TransactionCard(x, refresh)).toList()));
2024-09-07 21:56:52 +00:00
},
)
]),
floatingActionButton: FloatingActionButton(
onPressed: () {
2024-09-07 22:24:13 +00:00
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SupplyPage(widget.item, refresh)));
2024-09-07 21:56:52 +00:00
},
child: const Icon(Icons.add)),
);
}
}