2024-09-24 16:00:13 +00:00
|
|
|
import 'package:cdb_ui/api.dart' as API;
|
2024-09-24 16:35:28 +00:00
|
|
|
import 'package:cdb_ui/api.dart';
|
2024-09-25 16:14:42 +00:00
|
|
|
import 'package:cdb_ui/pages/supply.dart';
|
2024-09-24 16:35:28 +00:00
|
|
|
import 'package:cdb_ui/pages/transaction.dart';
|
2024-09-24 16:00:13 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2024-09-24 16:35:28 +00:00
|
|
|
class EndFlowWithProduce extends StatefulWidget {
|
2024-09-24 16:00:13 +00:00
|
|
|
final API.Flow flow;
|
|
|
|
final API.FlowInfo info;
|
|
|
|
|
|
|
|
const EndFlowWithProduce(this.flow, this.info, {super.key});
|
|
|
|
|
2024-09-24 16:35:28 +00:00
|
|
|
@override
|
|
|
|
State<EndFlowWithProduce> createState() => _EndFlowWithProduceState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _EndFlowWithProduceState extends State<EndFlowWithProduce> {
|
2024-09-25 16:14:42 +00:00
|
|
|
List<SupplyForm> produces = [];
|
|
|
|
late Map<String, Location> locations;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-09-26 19:35:28 +00:00
|
|
|
locations = API.API().getLocations();
|
2024-09-25 16:14:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
void addProduced(SupplyForm t) {
|
|
|
|
setState(() {
|
|
|
|
produces.add(t);
|
|
|
|
});
|
|
|
|
}
|
2024-09-24 16:35:28 +00:00
|
|
|
|
|
|
|
List<Widget> addProduceButtons() {
|
|
|
|
List<Widget> ret = [];
|
|
|
|
|
|
|
|
for (var i in widget.info.produces!) {
|
2024-09-26 19:35:28 +00:00
|
|
|
var (itemID, variant) = API.itemVariant(i);
|
|
|
|
var item = API.API().getItem(itemID);
|
2024-09-25 08:49:21 +00:00
|
|
|
ret.add(ElevatedButton(
|
|
|
|
onPressed: () {
|
2024-09-26 19:35:28 +00:00
|
|
|
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,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
));
|
2024-09-25 08:49:21 +00:00
|
|
|
},
|
2024-09-26 19:35:28 +00:00
|
|
|
child: Text("Produced ${item.variants[variant]!.name}")));
|
2024-09-24 16:35:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
_endFlow() {
|
|
|
|
API.API().endFlow(widget.flow.id, produced: produces).then((x) {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-09-24 16:00:13 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-09-24 16:35:28 +00:00
|
|
|
return Scaffold(
|
2024-09-25 08:49:21 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
title: Text("End ${widget.info.name} Flow"),
|
|
|
|
),
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
...addProduceButtons(),
|
|
|
|
const Divider(),
|
2024-09-25 16:14:42 +00:00
|
|
|
...produces.map((x) {
|
|
|
|
return TransactionCard(
|
|
|
|
x.transaction(locations),
|
|
|
|
() {},
|
|
|
|
onLongPress: (x) {},
|
|
|
|
onTap: (x) {},
|
|
|
|
);
|
|
|
|
}).toList(),
|
2024-09-25 08:49:21 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
ElevatedButton(onPressed: _endFlow, child: const Text("End Flow"))
|
|
|
|
],
|
|
|
|
),
|
2024-09-24 16:35:28 +00:00
|
|
|
);
|
2024-09-24 16:00:13 +00:00
|
|
|
}
|
2024-09-25 08:49:21 +00:00
|
|
|
}
|