From d3827c96c45784c38753592a09441c221820166d Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 21 Sep 2024 17:15:12 +0200 Subject: [PATCH] update --- lib/api.dart | 10 ++-- lib/pages/itemview.dart | 100 +--------------------------------- lib/pages/locations.dart | 2 +- lib/pages/stats.dart | 24 ++++++--- lib/pages/transaction.dart | 106 +++++++++++++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 111 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index 25033a9..ea6f3dc 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -295,9 +295,11 @@ class FlowInfo { FlowInfo(Map json) { id = json["id"]; name = json["name"]; - depends = json["depends"] as List; + depends = (json["depends"] as List).cast(); next = json["next"]; - produces = json["produces"]; + produces = json["produces"] != null + ? (json["produces"] as List).cast() + : null; } } @@ -450,7 +452,9 @@ class Flow { id = json["id"]; started = json["started"]; kind = json["kind"]; - input = json["input"]; + input = json["input"] != null + ? (json["input"] as List).cast() + : null; done = (json["done"] != null) ? FlowDone(json["done"]) : null; } } diff --git a/lib/pages/itemview.dart b/lib/pages/itemview.dart index ed592f4..3f78333 100644 --- a/lib/pages/itemview.dart +++ b/lib/pages/itemview.dart @@ -1,5 +1,5 @@ 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:intl/intl.dart'; import 'supply.dart'; @@ -112,101 +112,3 @@ class _ItemViewState extends State { ); } } - -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); -} diff --git a/lib/pages/locations.dart b/lib/pages/locations.dart index 2a0d945..5f14155 100644 --- a/lib/pages/locations.dart +++ b/lib/pages/locations.dart @@ -1,5 +1,5 @@ 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'; class LocationsPage extends StatelessWidget { diff --git a/lib/pages/stats.dart b/lib/pages/stats.dart index 85efb2f..ba7e3ec 100644 --- a/lib/pages/stats.dart +++ b/lib/pages/stats.dart @@ -1,5 +1,5 @@ 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'; class StatsPage extends StatelessWidget { @@ -37,13 +37,21 @@ class StatsPage extends StatelessWidget { return Column( children: [ Card( - child: Column( - children: [ - Text("Items: ${globalStat.item_count}"), - Text("Inventory: ${globalStat.total_transactions}"), - Text("Price: ${globalStat.total_price} €") - ], - )), + margin: EdgeInsets.all(10.0), + child: Padding( + padding: EdgeInsets.all(10.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + IconText(Icons.data_object, + "Items: ${globalStat.item_count}"), + IconText(Icons.list_alt, + "Inventory: ${globalStat.total_transactions}"), + IconText(Icons.money, + "Price: ${globalStat.total_price.toStringAsFixed(2)} €") + ], + ), + )), if (min.isNotEmpty) const ListTile(title: Text("Items under Minimum")), diff --git a/lib/pages/transaction.dart b/lib/pages/transaction.dart index 9cf28ae..63984e4 100644 --- a/lib/pages/transaction.dart +++ b/lib/pages/transaction.dart @@ -1,5 +1,7 @@ import 'package:cdb_ui/api.dart'; +import 'package:cdb_ui/pages/consume.dart'; import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; class TransactionPage extends StatelessWidget { 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), + ), + ], + ); + } +}