This commit is contained in:
JMARyA 2024-09-26 20:20:39 +02:00
parent cf1214e2ae
commit 4b2c8711df
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 197 additions and 100 deletions

View file

@ -4,6 +4,8 @@ import 'package:cdb_ui/pages/flow/end_flow_page.dart';
import 'package:cdb_ui/pages/flow/flow_note.dart';
import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart';
import 'package:qr_bar_code/qr/src/qr_code.dart';
import 'package:qr_bar_code/qr/src/types.dart';
class ActiveFlowPage extends StatefulWidget {
final API.Flow flow;
@ -80,40 +82,56 @@ class _ActiveFlowPageState extends State<ActiveFlowPage> {
icon: const Icon(Icons.arrow_forward)),
],
),
body: Column(
children: [
Text("ID: ${widget.flow.id}"),
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(),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 18.0),
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();
}
var data = snapshot.data!;
return Expanded(
child: ListView(
children: data
.map(
(x) => FlowNoteCard(x),
)
.toList()));
},
)
],
const Divider(),
FutureBuilder(
future: API.API().getNotesOfFlow(widget.flow.id),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return const CircularProgressIndicator();
}
var data = snapshot.data!;
return Expanded(
child: ListView(
children: data
.map(
(x) => FlowNoteCard(x),
)
.toList()));
},
)
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {

View file

@ -48,6 +48,7 @@ class FlowNoteCard extends StatelessWidget {
Widget build(BuildContext context) {
return Card(
child: ListTile(
dense: true,
title: Text(tsFormat(note.timestamp),
style: const TextStyle(fontSize: 12)),
subtitle: Text(note.content, overflow: TextOverflow.ellipsis),

View file

@ -1,8 +1,10 @@
import 'package:cdb_ui/api.dart' as API;
import 'package:cdb_ui/pages/expandable_list.dart';
import 'package:cdb_ui/pages/flow/active_flow_page.dart';
import 'package:cdb_ui/pages/flow/flow_info_page.dart';
import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart';
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
class FlowsPage extends StatefulWidget {
const FlowsPage({super.key});
@ -135,27 +137,51 @@ class _FlowsPageState extends State<FlowsPage> {
return DefaultTabController(
length: 4,
child: Scaffold(
appBar: AppBar(
title: const Text("Flows"),
bottom: TabBar(
tabs: const [
Tab(text: "All"),
Tab(text: "Produces"),
Tab(text: "Depends"),
Tab(text: "Active")
],
onTap: (value) {
setState(() {
tabSelection = value;
appBar: AppBar(
title: const Text("Flows"),
bottom: TabBar(
tabs: const [
Tab(text: "All"),
Tab(text: "Produces"),
Tab(text: "Depends"),
Tab(text: "Active")
],
onTap: (value) {
setState(() {
tabSelection = value;
});
},
)),
body: switch (tabSelection) {
0 => listAllFlowInfos(context, flowInfos!),
1 => listFlowInfoByProduced(context, flowInfos!),
2 => listFlowInfoByDependant(context, flowInfos!),
3 => listFlowInfoByActive(context, flowInfos!),
_ => const Text("..."),
},
floatingActionButton: FloatingActionButton(
onPressed: () {
// scan flow code
QrBarCodeScannerDialog().getScannedQrBarCode(
context: context,
onCode: (code) {
// library is retarded
code = code!.replaceFirst("Code scanned = ", "");
API.API().getFlow(code).then((flow) {
API.API().getFlowInfo(flow.kind).then((info) {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) {
return ActiveFlowPage(flow, info);
},
));
});
},
)),
body: switch (tabSelection) {
0 => listAllFlowInfos(context, flowInfos!),
1 => listFlowInfoByProduced(context, flowInfos!),
2 => listFlowInfoByDependant(context, flowInfos!),
3 => listFlowInfoByActive(context, flowInfos!),
_ => const Text("..."),
}));
});
},
);
},
child: const Icon(Icons.qr_code),
),
));
}
}

View file

@ -16,6 +16,26 @@ class TransactionPage extends StatefulWidget {
}
class _TransactionPageState extends State<TransactionPage> {
late Transaction transaction;
@override
void initState() {
super.initState();
transaction = widget.transaction;
}
Future<void> reload() async {
if (widget.refresh != null) {
widget.refresh!();
}
var updateTransaction = await API().getTransaction(transaction.uuid);
setState(() {
transaction = updateTransaction;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -102,56 +122,88 @@ class _TransactionPageState extends State<TransactionPage> {
icon: const Icon(Icons.move_up))
],
),
body: Column(
children: [
Text("UUID: ${widget.transaction.uuid}"),
QRCode(
data: widget.transaction.uuid,
size: 22,
semanticsLabel: "Transaction UUID",
),
// todo : human names
Text("${widget.transaction.item} - ${widget.transaction.variant}"),
Text("Added: ${tsFormat(widget.transaction.timestamp)}"),
if (widget.transaction.expired) const Text("Transaction is Expired!"),
IconText(Icons.money, widget.transaction.price.format(),
color: Colors.green),
if (widget.transaction.origin != null)
IconText(Icons.store, widget.transaction.origin!,
color: Colors.blue),
if (widget.transaction.location != null)
IconText(Icons.location_city, widget.transaction.location!.name),
if (widget.transaction.note != null) Text(widget.transaction.note!),
if (widget.transaction.consumed != null) ...[
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 18.0),
child: Column(
children: [
Row(
children: [
QRCode(
data: transaction.uuid,
size: 128,
eyeStyle: const QREyeStyle(color: Colors.white),
dataModuleStyle: const QRDataModuleStyle(color: Colors.white),
semanticsLabel: "Transaction UUID",
),
const SizedBox(
width: 16.0,
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// todo : human names
Text(
"${transaction.item}",
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 28),
),
Text(
"${transaction.variant}",
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.grey),
),
const SizedBox(
height: 8.0,
),
Text("Added: ${tsFormat(transaction.timestamp)}"),
],
)
],
),
const Divider(),
Text(
"Consumed on: ${tsFormat(widget.transaction.consumed!.timestamp)}"),
IconText(Icons.store, widget.transaction.consumed!.destination,
color: Colors.blue),
IconText(Icons.money, widget.transaction.consumed!.price.format(),
color: Colors.green),
]
const SizedBox(
height: 12.0,
),
// todo : chart with price history
],
if (transaction.expired) const Text("Transaction is Expired!"),
IconText(Icons.money, transaction.price.format(),
color: Colors.green),
if (transaction.origin != null)
IconText(Icons.store, transaction.origin!, color: Colors.blue),
if (transaction.location != null)
IconText(Icons.location_city, transaction.location!.name),
if (transaction.note != null) Text(transaction.note!),
if (transaction.consumed != null) ...[
const Divider(),
Text("Consumed on: ${tsFormat(transaction.consumed!.timestamp)}"),
IconText(Icons.store, transaction.consumed!.destination,
color: Colors.blue),
IconText(Icons.money, transaction.consumed!.price.format(),
color: Colors.green),
]
// todo : chart with price history
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (context) {
return ConsumePage(widget.transaction, widget.refresh ?? () {});
floatingActionButton: transaction.consumed == null
? FloatingActionButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) {
return ConsumePage(transaction, reload);
},
));
},
));
},
child: const Icon(Icons.receipt_long)),
child: const Icon(Icons.receipt_long))
: null,
);
}
}