2024-09-20 07:24:22 +00:00
|
|
|
import 'package:cdb_ui/api.dart';
|
2024-09-21 15:15:12 +00:00
|
|
|
import 'package:cdb_ui/pages/consume.dart';
|
2024-09-20 07:24:22 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-09-21 15:15:12 +00:00
|
|
|
import 'package:intl/intl.dart';
|
2024-09-20 07:24:22 +00:00
|
|
|
|
|
|
|
class TransactionPage extends StatelessWidget {
|
|
|
|
late Transaction transaction;
|
|
|
|
|
|
|
|
TransactionPage(this.transaction);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
// todo : transaction properties
|
|
|
|
// todo : chart with price history
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-09-21 15:15:12 +00:00
|
|
|
|
|
|
|
class TransactionCard extends StatelessWidget {
|
|
|
|
final Transaction t;
|
|
|
|
final Function refresh;
|
|
|
|
|
|
|
|
const TransactionCard(this.t, this.refresh, {super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return InkWell(
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) {
|
|
|
|
return ConsumePage(t.uuid, t.item, t.variant, refresh);
|
|
|
|
},
|
|
|
|
));
|
|
|
|
},
|
2024-09-22 20:15:43 +00:00
|
|
|
onLongPress: () {
|
|
|
|
Navigator.of(context).push(MaterialPageRoute(
|
|
|
|
builder: (context) {
|
|
|
|
return TransactionPage(t);
|
|
|
|
},
|
|
|
|
));
|
|
|
|
},
|
2024-09-21 15:15:12 +00:00
|
|
|
child: Card(
|
|
|
|
color: t.expired ? Colors.red[100] : Colors.black,
|
|
|
|
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
elevation: 4,
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
t.item,
|
|
|
|
style: const TextStyle(fontSize: 16),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 4,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
t.variant,
|
|
|
|
style: TextStyle(fontSize: 14, color: Colors.grey[400]),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
tsFormat(t.timestamp),
|
|
|
|
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
),
|
|
|
|
if ((t.note ?? "").isNotEmpty) ...[
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
Text(t.note!),
|
|
|
|
const SizedBox(
|
|
|
|
height: 10,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
IconText(Icons.money,
|
|
|
|
"${t.price.value.toStringAsFixed(2)} ${t.price.currency}",
|
|
|
|
color: Colors.green),
|
|
|
|
if (t.origin != null) ...[
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
IconText(Icons.store, t.origin!, color: Colors.blue)
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String tsFormat(int ts) {
|
|
|
|
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(ts * 1000);
|
|
|
|
return DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
class IconText extends StatelessWidget {
|
|
|
|
final IconData icon;
|
|
|
|
final String text;
|
|
|
|
final Color? color;
|
|
|
|
|
|
|
|
const IconText(this.icon, this.text, {super.key, this.color});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
Icon(icon, size: 18, color: color),
|
|
|
|
const SizedBox(width: 6),
|
|
|
|
Text(
|
|
|
|
text,
|
|
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|