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/flow/flow_note.dart';
import 'package:cdb_ui/pages/transaction.dart'; import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.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 { class ActiveFlowPage extends StatefulWidget {
final API.Flow flow; final API.Flow flow;
@ -80,10 +82,25 @@ class _ActiveFlowPageState extends State<ActiveFlowPage> {
icon: const Icon(Icons.arrow_forward)), icon: const Icon(Icons.arrow_forward)),
], ],
), ),
body: Column( body: Padding(
padding: EdgeInsets.symmetric(horizontal: 18.0),
child: Column(
children: [ children: [
Text("ID: ${widget.flow.id}"), 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)}"), Text("Started since: ${tsFormat(widget.flow.started)}"),
],
),
if (widget.flow.input != null) if (widget.flow.input != null)
...widget.flow.input!.map((x) => Text("Input: $x")).toList(), ...widget.flow.input!.map((x) => Text("Input: $x")).toList(),
if (widget.flow.done != null) ...[ if (widget.flow.done != null) ...[
@ -115,6 +132,7 @@ class _ActiveFlowPageState extends State<ActiveFlowPage> {
) )
], ],
), ),
),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () { onPressed: () {
Navigator.of(context).push(MaterialPageRoute( Navigator.of(context).push(MaterialPageRoute(

View file

@ -48,6 +48,7 @@ class FlowNoteCard extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Card( return Card(
child: ListTile( child: ListTile(
dense: true,
title: Text(tsFormat(note.timestamp), title: Text(tsFormat(note.timestamp),
style: const TextStyle(fontSize: 12)), style: const TextStyle(fontSize: 12)),
subtitle: Text(note.content, overflow: TextOverflow.ellipsis), 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/api.dart' as API;
import 'package:cdb_ui/pages/expandable_list.dart'; 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/flow/flow_info_page.dart';
import 'package:cdb_ui/pages/transaction.dart'; import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart';
class FlowsPage extends StatefulWidget { class FlowsPage extends StatefulWidget {
const FlowsPage({super.key}); const FlowsPage({super.key});
@ -156,6 +158,30 @@ class _FlowsPageState extends State<FlowsPage> {
2 => listFlowInfoByDependant(context, flowInfos!), 2 => listFlowInfoByDependant(context, flowInfos!),
3 => listFlowInfoByActive(context, flowInfos!), 3 => listFlowInfoByActive(context, flowInfos!),
_ => const Text("..."), _ => 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);
},
));
});
});
},
);
},
child: const Icon(Icons.qr_code),
),
));
} }
} }

View file

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