import 'package:cdb_ui/api.dart' as API; import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/pages/supply.dart'; import 'package:cdb_ui/pages/transaction.dart'; import 'package:flutter/material.dart'; class EndFlowWithProduce extends StatefulWidget { final API.Flow flow; final API.FlowInfo info; const EndFlowWithProduce(this.flow, this.info, {super.key}); @override State createState() => _EndFlowWithProduceState(); } class _EndFlowWithProduceState extends State { List produces = []; late Map locations; @override void initState() { super.initState(); locations = API.API().getLocations(); } refresh() { setState(() {}); } void addProduced(SupplyForm t) { setState(() { produces.add(t); }); } List addProduceButtons() { List ret = []; for (var i in widget.info.produces!) { var (itemID, variant) = API.itemVariant(i); var item = API.API().getItem(itemID); ret.add(ElevatedButton( onPressed: () { Navigator.of(context).push(MaterialPageRoute( builder: (context) { return SupplyPage( item, refresh, onlyVariants: [variant], forcePrice: "0.00", forceOrigin: "flow::${widget.flow.kind}::${widget.flow.id}", onCreate: addProduced, ); }, )); }, child: Text("Produced ${item.variants[variant]!.name}"))); } return ret; } _endFlow() { API.API().endFlow(widget.flow.id, produced: produces).then((x) { Navigator.of(context).pop(); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("End ${widget.info.name} Flow"), ), body: Column( children: [ ...addProduceButtons(), const Divider(), ...produces.map((x) { return TransactionCard( x.transaction(locations), () {}, onLongPress: (x) {}, onTap: (x) {}, ); }).toList(), const SizedBox( height: 10, ), ElevatedButton(onPressed: _endFlow, child: const Text("End Flow")) ], ), ); } }