2024-09-24 16:00:13 +00:00
|
|
|
import 'package:cdb_ui/api.dart' as API;
|
|
|
|
import 'package:cdb_ui/pages/flow/create_flow_page.dart';
|
|
|
|
import 'package:cdb_ui/pages/flow/end_flow_page.dart';
|
2024-09-25 07:02:50 +00:00
|
|
|
import 'package:cdb_ui/pages/flow/flow_note.dart';
|
2024-09-24 16:00:13 +00:00
|
|
|
import 'package:cdb_ui/pages/transaction.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-09-26 18:20:39 +00:00
|
|
|
import 'package:qr_bar_code/qr/src/qr_code.dart';
|
|
|
|
import 'package:qr_bar_code/qr/src/types.dart';
|
2024-09-24 16:00:13 +00:00
|
|
|
|
2024-09-25 07:02:50 +00:00
|
|
|
class ActiveFlowPage extends StatefulWidget {
|
2024-09-24 16:00:13 +00:00
|
|
|
final API.Flow flow;
|
|
|
|
final API.FlowInfo info;
|
|
|
|
|
|
|
|
const ActiveFlowPage(this.flow, this.info, {super.key});
|
|
|
|
|
2024-09-25 07:02:50 +00:00
|
|
|
@override
|
|
|
|
State<ActiveFlowPage> createState() => _ActiveFlowPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ActiveFlowPageState extends State<ActiveFlowPage> {
|
|
|
|
_refresh() {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
2024-09-24 16:00:13 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2024-09-25 07:02:50 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(widget.info.name),
|
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () async {
|
|
|
|
if (widget.info.produces?.isNotEmpty ?? false) {
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) =>
|
|
|
|
EndFlowWithProduce(widget.flow, widget.info)));
|
|
|
|
return;
|
|
|
|
}
|
2024-09-24 16:00:13 +00:00
|
|
|
|
2024-09-25 07:02:50 +00:00
|
|
|
// simple dialog
|
|
|
|
var confirm = await showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: const Text('Are you sure?'),
|
|
|
|
content: const Text('This will end the flow.'),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(false),
|
|
|
|
child: const Text('Cancel'),
|
|
|
|
),
|
|
|
|
ElevatedButton(
|
|
|
|
onPressed: () => Navigator.of(context).pop(true),
|
|
|
|
child: const Text('End'),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2024-09-24 16:00:13 +00:00
|
|
|
|
2024-09-26 19:01:45 +00:00
|
|
|
if (confirm ?? false) {
|
2024-09-25 07:02:50 +00:00
|
|
|
await API
|
|
|
|
.API()
|
|
|
|
.endFlow(widget.flow.id)
|
|
|
|
.then((x) => Navigator.of(context).pop());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.stop)),
|
|
|
|
if (widget.info.next != null)
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
2024-09-26 19:35:28 +00:00
|
|
|
var newInfo = API.API().getFlowInfo(widget.info.next!);
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) {
|
|
|
|
return CreateFlowPage(
|
|
|
|
newInfo,
|
|
|
|
() {},
|
|
|
|
previousFlow: widget.flow,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
));
|
2024-09-24 16:00:13 +00:00
|
|
|
},
|
2024-09-25 07:02:50 +00:00
|
|
|
icon: const Icon(Icons.arrow_forward)),
|
|
|
|
],
|
|
|
|
),
|
2024-09-26 18:20:39 +00:00
|
|
|
body: Padding(
|
2024-10-08 08:55:30 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 18.0),
|
2024-09-26 18:20:39 +00:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
QRCode(
|
|
|
|
data: widget.flow.id,
|
|
|
|
size: 128,
|
|
|
|
eyeStyle: const QREyeStyle(color: Colors.white),
|
|
|
|
dataModuleStyle: const QRDataModuleStyle(color: Colors.white),
|
|
|
|
semanticsLabel: "Transaction UUID",
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 16.0,
|
|
|
|
),
|
|
|
|
Text("Started since: ${tsFormat(widget.flow.started)}"),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
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)
|
|
|
|
Text("Next: ${widget.flow.done!.next!}"),
|
|
|
|
...widget.flow.done!.produced!
|
|
|
|
.map((x) => Text("Produced: $x"))
|
|
|
|
.toList(),
|
|
|
|
],
|
|
|
|
const Divider(),
|
|
|
|
FutureBuilder(
|
|
|
|
future: API.API().getNotesOfFlow(widget.flow.id),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData) {
|
|
|
|
return const CircularProgressIndicator();
|
|
|
|
}
|
2024-09-24 16:00:13 +00:00
|
|
|
|
2024-09-26 18:20:39 +00:00
|
|
|
var data = snapshot.data!;
|
2024-09-25 07:02:50 +00:00
|
|
|
|
2024-09-26 18:20:39 +00:00
|
|
|
return Expanded(
|
|
|
|
child: ListView(
|
|
|
|
children: data
|
|
|
|
.map(
|
|
|
|
(x) => FlowNoteCard(x),
|
|
|
|
)
|
|
|
|
.toList()));
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2024-09-25 07:02:50 +00:00
|
|
|
),
|
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) => AddNotePage(widget.flow, _refresh)));
|
|
|
|
},
|
|
|
|
child: const Icon(Icons.note_add),
|
|
|
|
),
|
|
|
|
);
|
2024-09-24 16:00:13 +00:00
|
|
|
}
|
|
|
|
}
|