diff --git a/lib/api.dart b/lib/api.dart index 3f6f4fd..1ae5dc6 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -286,8 +286,6 @@ class API { var resp = jsonDecode(await postRequest("$instance/flow/$id/end", {"produced": produced?.map((x) => x.json()).toList()})); - print(resp); - if (produced != null) { var produced = resp["produced"] as Map; return produced.map( @@ -385,6 +383,7 @@ class ItemVariant { late String name; int? min; int? expiry; + List? barcodes; ItemVariant(Map json) { item = json["item"]; @@ -392,6 +391,9 @@ class ItemVariant { name = json["name"]; min = json["min"]; expiry = json["expiry"]; + barcodes = json["barcodes"] != null + ? (json["barcodes"] as List).cast() + : null; } } @@ -549,14 +551,14 @@ class FlowNote { } class GlobalItemStat { - late int item_count; - late int total_transactions; - late double total_price; + late int itemCount; + late int totalTransactions; + late double totalPrice; GlobalItemStat(Map json) { - item_count = json["item_count"]; - total_transactions = json["total_transactions"]; - total_price = json["total_price"]; + itemCount = json["item_count"]; + totalTransactions = json["total_transactions"]; + totalPrice = json["total_price"]; } } @@ -581,11 +583,11 @@ class FullItemVariantStat { } class OriginStat { - late double average_price; + late double averagePrice; late int inventory; OriginStat(Map json) { - average_price = json["average_price"]; + averagePrice = json["average_price"]; inventory = json["inventory"]; } } diff --git a/lib/pages/flow/active_flow_page.dart b/lib/pages/flow/active_flow_page.dart index 12eff76..d43b74e 100644 --- a/lib/pages/flow/active_flow_page.dart +++ b/lib/pages/flow/active_flow_page.dart @@ -82,7 +82,7 @@ class _ActiveFlowPageState extends State { ], ), body: Padding( - padding: EdgeInsets.symmetric(horizontal: 18.0), + padding: const EdgeInsets.symmetric(horizontal: 18.0), child: Column( children: [ Row( diff --git a/lib/pages/flow/create_flow_page.dart b/lib/pages/flow/create_flow_page.dart index 0998424..35d5fb2 100644 --- a/lib/pages/flow/create_flow_page.dart +++ b/lib/pages/flow/create_flow_page.dart @@ -94,7 +94,7 @@ class _CreateFlowPageState extends State { child: Text(API.API().getFlowInfo(widget.previousFlow!.kind).name), ), ), - Card(child: Icon(Icons.arrow_right)), + const Card(child: Icon(Icons.arrow_right)), Card( child: Padding( padding: const EdgeInsets.all(8.0), diff --git a/lib/pages/items.dart b/lib/pages/items.dart index 71fc15c..b4daa87 100644 --- a/lib/pages/items.dart +++ b/lib/pages/items.dart @@ -7,11 +7,40 @@ import 'package:flutter/material.dart'; class ItemsPage extends StatelessWidget { const ItemsPage({super.key}); + _scanBarcodeSupply(BuildContext context) async { + var code = + int.parse(await scanQRCode(context, title: "Scan Barcode") ?? "0"); + + var items = API().getItems(); + for (var item in items) { + for (var variant in item.variants.keys) { + for (var barcode in item.variants[variant]!.barcodes ?? []) { + if (code == barcode) { + Navigator.of(context).push(MaterialPageRoute( + builder: (context) => SupplyPage( + item, + () {}, + onlyVariants: [variant], + ))); + } + } + } + } + } + @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("Items"), + // todo : add barcode scan + actions: [ + ElevatedButton( + onPressed: () { + _scanBarcodeSupply(context); + }, + child: const Icon(Icons.add_box)) + ], ), body: ListView( children: API().getItems().map((x) { diff --git a/lib/pages/itemview.dart b/lib/pages/itemview.dart index ab9e418..a6e7363 100644 --- a/lib/pages/itemview.dart +++ b/lib/pages/itemview.dart @@ -2,7 +2,6 @@ import 'package:cdb_ui/api.dart'; import 'package:cdb_ui/pages/stats.dart'; import 'package:cdb_ui/pages/transaction.dart'; import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; import 'supply.dart'; // todo : show est. time remaining until inventory gets empty (based on demand) @@ -33,7 +32,7 @@ class _ItemViewState extends State { builder: (context) => ItemStatPage(widget.item), )); }, - icon: Icon(Icons.bar_chart)) + icon: const Icon(Icons.bar_chart)) ], ), body: Column(children: [ diff --git a/lib/pages/locations.dart b/lib/pages/locations.dart index 5ddb754..5e62a79 100644 --- a/lib/pages/locations.dart +++ b/lib/pages/locations.dart @@ -107,7 +107,7 @@ class _LocationViewState extends State { title: Text(widget.location.name), ), body: Padding( - padding: EdgeInsets.symmetric(horizontal: 10.0), + padding: const EdgeInsets.symmetric(horizontal: 10.0), child: Column( children: [ Card( diff --git a/lib/pages/stats.dart b/lib/pages/stats.dart index 91ddd66..cb99e2a 100644 --- a/lib/pages/stats.dart +++ b/lib/pages/stats.dart @@ -24,7 +24,9 @@ class StatsPage extends StatelessWidget { // global origin / destinations return Scaffold( - appBar: AppBar(title: Text("Home"),), + appBar: AppBar( + title: const Text("Home"), + ), body: FutureBuilder( future: _fetchData(), builder: (context, snapshot) { @@ -47,11 +49,11 @@ class StatsPage extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ IconText(Icons.data_object, - "Items: ${globalStat.item_count}"), + "Items: ${globalStat.itemCount}"), IconText(Icons.list_alt, - "Inventory: ${globalStat.total_transactions}"), + "Inventory: ${globalStat.totalTransactions}"), IconText(Icons.money, - "Price: ${globalStat.total_price.toStringAsFixed(2)} €") + "Price: ${globalStat.totalPrice.toStringAsFixed(2)} €") ], ), )), @@ -110,7 +112,7 @@ class ItemStatPage extends StatelessWidget { return Column(children: [ Text("Inventory: ${originStat.inventory}"), Text( - "Average Price: ${originStat.average_price.toStringAsFixed(2)} €"), + "Average Price: ${originStat.averagePrice.toStringAsFixed(2)} €"), ]); }).toList() ], diff --git a/lib/pages/transaction.dart b/lib/pages/transaction.dart index acad5dc..79e674d 100644 --- a/lib/pages/transaction.dart +++ b/lib/pages/transaction.dart @@ -132,12 +132,15 @@ class _TransactionPageState extends State { children: [ // todo : human names Text( - "${API().getItem(transaction.item).name}", + API().getItem(transaction.item).name, style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 28), ), Text( - "${API().getItem(transaction.item).variants[transaction.variant]!.name}", + API() + .getItem(transaction.item) + .variants[transaction.variant]! + .name, style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 20, @@ -355,7 +358,7 @@ class TransactionSelectPage extends StatelessWidget { body: ListView( children: selectionList.isEmpty ? [ - ListTile( + const ListTile( title: Center(child: Text("No Transactions available")), ) ]