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:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:qr_bar_code/qr/qr.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 Transaction transaction;
|
||||||
final Function? refresh;
|
final Function? refresh;
|
||||||
|
|
||||||
const TransactionPage(this.transaction, {this.refresh, super.key});
|
const TransactionPage(this.transaction, {this.refresh, super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<TransactionPage> createState() => _TransactionPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TransactionPageState extends State<TransactionPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(transaction.item),
|
title: Text(widget.transaction.item),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
@ -34,6 +40,14 @@ class TransactionPage extends StatelessWidget {
|
||||||
value: selectedLocationID,
|
value: selectedLocationID,
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
selectedLocationID = value!;
|
selectedLocationID = value!;
|
||||||
|
API()
|
||||||
|
.moveTransaction(widget.transaction.uuid,
|
||||||
|
selectedLocationID!)
|
||||||
|
.then((x) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
});
|
||||||
|
|
||||||
|
setState(() {});
|
||||||
},
|
},
|
||||||
items: locationList
|
items: locationList
|
||||||
.map<DropdownMenuItem<String>>((locationID) {
|
.map<DropdownMenuItem<String>>((locationID) {
|
||||||
|
@ -45,21 +59,39 @@ class TransactionPage extends StatelessWidget {
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () {
|
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))
|
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(
|
body: Column(
|
||||||
children: [
|
children: [
|
||||||
Text("UUID: ${transaction.uuid}"),
|
Text("UUID: ${widget.transaction.uuid}"),
|
||||||
QRCode(
|
QRCode(
|
||||||
data: transaction.uuid,
|
data: widget.transaction.uuid,
|
||||||
size: 22,
|
size: 22,
|
||||||
semanticsLabel: "Transaction UUID",
|
semanticsLabel: "Transaction UUID",
|
||||||
),
|
),
|
||||||
|
|
||||||
// todo : human names
|
// 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),
|
color: Colors.green),
|
||||||
|
|
||||||
if (transaction.origin != null)
|
if (widget.transaction.origin != null)
|
||||||
IconText(Icons.store, transaction.origin!, color: Colors.blue),
|
IconText(Icons.store, widget.transaction.origin!,
|
||||||
|
|
||||||
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),
|
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),
|
color: Colors.green),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -110,7 +144,7 @@ class TransactionPage extends StatelessWidget {
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return ConsumePage(transaction, refresh ?? () {});
|
return ConsumePage(widget.transaction, widget.refresh ?? () {});
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue