move update
This commit is contained in:
parent
2cd3e589db
commit
710ea6743b
1 changed files with 67 additions and 33 deletions
|
@ -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<TransactionPage> createState() => _TransactionPageState();
|
||||
}
|
||||
|
||||
class _TransactionPageState extends State<TransactionPage> {
|
||||
@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<DropdownMenuItem<String>>((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<int>(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 ?? () {});
|
||||
},
|
||||
));
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue