118 lines
3.8 KiB
Dart
118 lines
3.8 KiB
Dart
import 'package:cdb_ui/api.dart';
|
|
import 'package:cdb_ui/pages/home.dart';
|
|
import 'package:cdb_ui/pages/transaction.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'supply.dart';
|
|
|
|
// todo : show est. time remaining until inventory gets empty (based on demand)
|
|
|
|
class ItemView extends StatefulWidget {
|
|
final Item item;
|
|
|
|
@override
|
|
State<ItemView> createState() => _ItemViewState();
|
|
|
|
const ItemView({super.key, required this.item});
|
|
}
|
|
|
|
class _ItemViewState extends State<ItemView> {
|
|
void refresh() {
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text(widget.item.name)),
|
|
body: Column(children: [
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 28),
|
|
child: Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: widget.item.image != null
|
|
? Image.network(
|
|
"${API().instance}/${widget.item.image}",
|
|
height: 100,
|
|
width: 100,
|
|
)
|
|
: null,
|
|
),
|
|
const SizedBox(
|
|
width: 16.0,
|
|
),
|
|
Column(
|
|
children: [
|
|
Text(
|
|
widget.item.name,
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
if (widget.item.category != null)
|
|
Text(widget.item.category!),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
const SizedBox(height: 18),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: widget.item.variants.entries.map((entry) {
|
|
return Column(children: [
|
|
Text(
|
|
entry.value.name,
|
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
FutureBuilder(
|
|
future: API().getStat(widget.item.id, entry.key),
|
|
builder: (context, snapshot) {
|
|
if (!snapshot.hasData) {
|
|
return const CircularProgressIndicator();
|
|
}
|
|
|
|
var stat = snapshot.data!;
|
|
|
|
return Column(
|
|
children: [
|
|
Text("Amount: ${stat.amount}"),
|
|
Text(
|
|
"Total Cost: ${stat.totalPrice.toStringAsFixed(2)}")
|
|
],
|
|
);
|
|
},
|
|
)
|
|
]);
|
|
}).toList()),
|
|
const SizedBox(
|
|
height: 12,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
FutureBuilder(
|
|
future: API().getInventory(widget.item.id),
|
|
builder: (context, snapshot) {
|
|
if (!snapshot.hasData) {
|
|
return const CircularProgressIndicator();
|
|
}
|
|
var data = snapshot.data!;
|
|
|
|
return Expanded(
|
|
child: ListView(
|
|
children:
|
|
data.map((x) => TransactionCard(x, refresh)).toList()));
|
|
},
|
|
)
|
|
]),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (context) => SupplyPage(widget.item, refresh)));
|
|
},
|
|
child: const Icon(Icons.add)),
|
|
);
|
|
}
|
|
}
|