add produce flows

This commit is contained in:
JMARyA 2024-09-25 18:14:42 +02:00
parent 3da48add7e
commit 70b798f65f
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 192 additions and 48 deletions

View file

@ -85,7 +85,8 @@ class _ActiveFlowPageState extends State<ActiveFlowPage> {
children: [
Text("ID: ${widget.flow.id}"),
Text("Started since: ${tsFormat(widget.flow.started)}"),
...widget.flow.input!.map((x) => Text("Input: $x")).toList(),
if (widget.flow.input != null)
...widget.flow.input!.map((x) => Text("Input: $x")).toList(),
if (widget.flow.done != null) ...[
Text("Ended: ${tsFormat(widget.flow.done!.ended)}"),
if (widget.flow.done!.next != null)

View file

@ -1,5 +1,8 @@
import 'dart:js_interop_unsafe';
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';
@ -14,7 +17,30 @@ class EndFlowWithProduce extends StatefulWidget {
}
class _EndFlowWithProduceState extends State<EndFlowWithProduce> {
Map<String, int> produces = {};
List<SupplyForm> produces = [];
late Map<String, Location> locations;
@override
void initState() {
super.initState();
API.API().getLocations().then(
(value) {
setState(() {
locations = value;
});
},
);
}
refresh() {
setState(() {});
}
void addProduced(SupplyForm t) {
setState(() {
produces.add(t);
});
}
List<Widget> addProduceButtons() {
List<Widget> ret = [];
@ -22,7 +48,21 @@ class _EndFlowWithProduceState extends State<EndFlowWithProduce> {
for (var i in widget.info.produces!) {
ret.add(ElevatedButton(
onPressed: () {
// todo : implement adding
var (itemID, variant) = API.itemVariant(i);
API.API().getItem(itemID).then((item) {
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 $i")));
}
@ -48,6 +88,14 @@ class _EndFlowWithProduceState extends State<EndFlowWithProduce> {
...addProduceButtons(),
const Divider(),
// todo : add produced list
...produces.map((x) {
return TransactionCard(
x.transaction(locations),
() {},
onLongPress: (x) {},
onTap: (x) {},
);
}).toList(),
const SizedBox(
height: 10,
),

View file

@ -9,7 +9,7 @@ class AddNotePage extends StatelessWidget {
AddNotePage(this.flow, this.refresh, {super.key});
_submit(BuildContext context) {
void _submit(BuildContext context) {
API.API().addNoteToFlow(flow.id, _noteController.text).then((x) {
refresh();
Navigator.of(context).pop();
@ -32,7 +32,7 @@ class AddNotePage extends StatelessWidget {
height: 14,
),
ElevatedButton(
onPressed: _submit(context), child: const Text("Add Note"))
onPressed: () => _submit(context), child: const Text("Add Note"))
],
),
);