From 710ea6743bb7e74871d10927d7e149c17027621d Mon Sep 17 00:00:00 2001 From: JMARyA Date: Tue, 24 Sep 2024 16:19:15 +0200 Subject: [PATCH] move update --- lib/pages/transaction.dart | 100 +++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 33 deletions(-) diff --git a/lib/pages/transaction.dart b/lib/pages/transaction.dart index d0d64c9..66a7e73 100644 --- a/lib/pages/transaction.dart +++ b/lib/pages/transaction.dart @@ -3,18 +3,24 @@ import 'package:cdb_ui/pages/consume.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:qr_bar_code/qr/qr.dart'; +import 'package:qr_bar_code_scanner_dialog/qr_bar_code_scanner_dialog.dart'; -class TransactionPage extends StatelessWidget { +class TransactionPage extends StatefulWidget { final Transaction transaction; final Function? refresh; const TransactionPage(this.transaction, {this.refresh, super.key}); + @override + State createState() => _TransactionPageState(); +} + +class _TransactionPageState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text(transaction.item), + title: Text(widget.transaction.item), actions: [ IconButton( onPressed: () async { @@ -34,6 +40,14 @@ class TransactionPage extends StatelessWidget { value: selectedLocationID, onChanged: (value) { selectedLocationID = value!; + API() + .moveTransaction(widget.transaction.uuid, + selectedLocationID!) + .then((x) { + Navigator.of(context).pop(); + }); + + setState(() {}); }, items: locationList .map>((locationID) { @@ -45,21 +59,39 @@ class TransactionPage extends StatelessWidget { ), IconButton( onPressed: () { - // todo : implement + API().getLocations().then((locations) { + QrBarCodeScannerDialog().getScannedQrBarCode( + context: context, + onCode: (code) { + // library is retarded + code = code!.replaceFirst( + "Code scanned = ", ""); + if (!locations.containsKey(code)) { + ScaffoldMessenger.of(context) + .showSnackBar( + SnackBar( + content: Text( + 'The location $code does not exist.')), + ); + return; + } + + API() + .moveTransaction( + widget.transaction.uuid, + selectedLocationID!) + .then( + (x) { + Navigator.of(context).pop(); + }, + ); + }); + }); + setState(() {}); }, icon: const Icon(Icons.qr_code)) ], ), - actions: [ - ElevatedButton( - onPressed: () async { - await API().moveTransaction( - transaction.uuid, selectedLocationID!); - Navigator.pop(context); - }, - child: const Text('Done'), - ), - ], ); }, ); @@ -69,37 +101,39 @@ class TransactionPage extends StatelessWidget { ), body: Column( children: [ - Text("UUID: ${transaction.uuid}"), + Text("UUID: ${widget.transaction.uuid}"), QRCode( - data: transaction.uuid, + data: widget.transaction.uuid, size: 22, semanticsLabel: "Transaction UUID", ), // todo : human names - Text("${transaction.item} - ${transaction.variant}"), + Text("${widget.transaction.item} - ${widget.transaction.variant}"), - Text("Added: ${tsFormat(transaction.timestamp)}"), + 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), - 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, + if (widget.transaction.origin != null) + IconText(Icons.store, widget.transaction.origin!, color: Colors.blue), - IconText(Icons.money, transaction.consumed!.price.format(), + + 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) ...[ + 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), ] @@ -110,7 +144,7 @@ class TransactionPage extends StatelessWidget { onPressed: () { Navigator.of(context).pushReplacement(MaterialPageRoute( builder: (context) { - return ConsumePage(transaction, refresh ?? () {}); + return ConsumePage(widget.transaction, widget.refresh ?? () {}); }, )); },