This commit is contained in:
JMARyA 2024-09-21 17:15:12 +02:00
parent fd2f2aa6f5
commit d3827c96c4
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 131 additions and 111 deletions

View file

@ -295,9 +295,11 @@ class FlowInfo {
FlowInfo(Map<String, dynamic> json) { FlowInfo(Map<String, dynamic> json) {
id = json["id"]; id = json["id"];
name = json["name"]; name = json["name"];
depends = json["depends"] as List<String>; depends = (json["depends"] as List<dynamic>).cast<String>();
next = json["next"]; next = json["next"];
produces = json["produces"]; produces = json["produces"] != null
? (json["produces"] as List<dynamic>).cast<String>()
: null;
} }
} }
@ -450,7 +452,9 @@ class Flow {
id = json["id"]; id = json["id"];
started = json["started"]; started = json["started"];
kind = json["kind"]; kind = json["kind"];
input = json["input"]; input = json["input"] != null
? (json["input"] as List<dynamic>).cast<String>()
: null;
done = (json["done"] != null) ? FlowDone(json["done"]) : null; done = (json["done"] != null) ? FlowDone(json["done"]) : null;
} }
} }

View file

@ -1,5 +1,5 @@
import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/api.dart';
import 'package:cdb_ui/pages/consume.dart'; import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'supply.dart'; import 'supply.dart';
@ -112,101 +112,3 @@ class _ItemViewState extends State<ItemView> {
); );
} }
} }
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);
},
));
},
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) ...[
Text(t.note!),
const SizedBox(
height: 10,
)
],
Row(
children: [
const Icon(Icons.money, size: 18, color: Colors.green),
const SizedBox(width: 6),
Text(
"${t.price.value.toStringAsFixed(2)} ${t.price.currency}",
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.bold),
),
],
),
if (t.origin != null) ...[
const SizedBox(height: 8),
Row(
children: [
const Icon(Icons.store, size: 18, color: Colors.blue),
const SizedBox(width: 6),
Text(
t.origin!,
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
),
],
),
],
],
),
),
),
);
}
}
String tsFormat(int ts) {
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(ts * 1000);
return DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
}

View file

@ -1,5 +1,5 @@
import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/api.dart';
import 'package:cdb_ui/pages/itemview.dart'; import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class LocationsPage extends StatelessWidget { class LocationsPage extends StatelessWidget {

View file

@ -1,5 +1,5 @@
import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/api.dart';
import 'package:cdb_ui/pages/itemview.dart'; import 'package:cdb_ui/pages/transaction.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class StatsPage extends StatelessWidget { class StatsPage extends StatelessWidget {
@ -37,12 +37,20 @@ class StatsPage extends StatelessWidget {
return Column( return Column(
children: [ children: [
Card( Card(
child: Column( margin: EdgeInsets.all(10.0),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text("Items: ${globalStat.item_count}"), IconText(Icons.data_object,
Text("Inventory: ${globalStat.total_transactions}"), "Items: ${globalStat.item_count}"),
Text("Price: ${globalStat.total_price}") IconText(Icons.list_alt,
"Inventory: ${globalStat.total_transactions}"),
IconText(Icons.money,
"Price: ${globalStat.total_price.toStringAsFixed(2)}")
], ],
),
)), )),
if (min.isNotEmpty) if (min.isNotEmpty)

View file

@ -1,5 +1,7 @@
import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/api.dart';
import 'package:cdb_ui/pages/consume.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class TransactionPage extends StatelessWidget { class TransactionPage extends StatelessWidget {
late Transaction transaction; late Transaction transaction;
@ -18,3 +20,107 @@ class TransactionPage extends StatelessWidget {
); );
} }
} }
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);
},
));
},
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),
),
],
);
}
}