102 lines
No EOL
2.9 KiB
Dart
102 lines
No EOL
2.9 KiB
Dart
import 'package:cdb_ui/api.dart' as API;
|
|
import 'package:cdb_ui/pages/flow/active_flow_page.dart';
|
|
import 'package:cdb_ui/pages/transaction.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
class CreateFlowPage extends StatefulWidget {
|
|
final API.FlowInfo info;
|
|
final Function refresh;
|
|
final API.Flow? previousFlow;
|
|
|
|
const CreateFlowPage(this.info, this.refresh, {this.previousFlow, super.key});
|
|
|
|
@override
|
|
State<CreateFlowPage> createState() => _CreateFlowPageState();
|
|
}
|
|
|
|
class _CreateFlowPageState extends State<CreateFlowPage> {
|
|
List<API.Transaction> depends = [];
|
|
|
|
void _create(BuildContext context) {
|
|
if (widget.previousFlow != null) {
|
|
API
|
|
.API()
|
|
.continueFlow(widget.previousFlow!.id,
|
|
input: depends.map((x) => x.uuid).toList())
|
|
.then((x) {
|
|
API.API().getFlow(x).then((flow) {
|
|
API.API().getFlowInfo(flow.kind).then((info) {
|
|
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
|
builder: (context) => ActiveFlowPage(flow, info),
|
|
));
|
|
});
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
|
|
API
|
|
.API()
|
|
.startFlow(widget.info.id, input: depends.map((x) => x.uuid).toList())
|
|
.then((flowID) {
|
|
widget.refresh();
|
|
API.API().getFlow(flowID).then((flow) {
|
|
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
|
builder: (context) => ActiveFlowPage(flow, widget.info)));
|
|
});
|
|
});
|
|
}
|
|
|
|
void selectDependItems(BuildContext context, String itemVariant) {
|
|
var (item, variant) = API.itemVariant(itemVariant);
|
|
|
|
API.API().getInventoryOfVariant(item, variant).then((transactions) {
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
builder: (context) {
|
|
return TransactionSelectPage(transactions, onSelect: (t) {
|
|
if (!depends.contains(t)) {
|
|
setState(() {
|
|
depends.add(t);
|
|
});
|
|
}
|
|
}, exclude: depends);
|
|
},
|
|
));
|
|
});
|
|
}
|
|
|
|
Widget buildInputSelection(BuildContext context) {
|
|
return Column(
|
|
children: widget.info.depends.map((x) {
|
|
return ElevatedButton(
|
|
onPressed: () {
|
|
selectDependItems(context, x);
|
|
},
|
|
child: Text("Add $x"));
|
|
}).toList());
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text("Create new ${widget.info.name} Flow")),
|
|
body: Column(
|
|
children: [
|
|
// todo : flow continuation overview
|
|
buildInputSelection(context),
|
|
const Divider(),
|
|
Card(
|
|
child: Column(
|
|
children: depends
|
|
.map((x) => TransactionCard(x, () {},
|
|
onTap: (x) {}, onLongPress: (x) {}))
|
|
.toList())),
|
|
ElevatedButton(
|
|
onPressed: () => _create(context),
|
|
child: const Text("Create Flow"))
|
|
],
|
|
),
|
|
);
|
|
}
|
|
} |