cdb_ui/lib/pages/itemview.dart

117 lines
3.6 KiB
Dart
Raw Normal View History

2024-09-07 21:56:52 +00:00
import 'package:cdb_ui/api.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 'package:intl/intl.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-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: [
const Align(
alignment: Alignment.centerLeft,
child: Placeholder(
fallbackWidth: 100,
fallbackHeight: 100,
),
), // todo
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),
),
Text(widget.item.category),
],
)
],
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)),
);
}
}