import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/pages/stats.dart'; import 'package:cdb_ui/pages/transaction.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.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 createState() => _ItemViewState(); const ItemView({super.key, required this.item}); } class _ItemViewState extends State { void refresh() { setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.item.name), actions: [ IconButton( onPressed: () { Navigator.of(context).push(MaterialPageRoute( builder: (context) => ItemStatPage(widget.item), )); }, icon: Icon(Icons.bar_chart)) ], ), body: Column(children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 28), child: Column( children: [ Row( mainAxisAlignment: MainAxisAlignment.start, children: [ const Align( alignment: Alignment.centerLeft, child: Placeholder( fallbackWidth: 100, fallbackHeight: 100, ), ), 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)), ); } }