From 4b9e6165815852067724476f92d31d0bb7844de2 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Sat, 21 Sep 2024 01:37:11 +0200 Subject: [PATCH] add notes --- lib/api.dart | 11 +++++++++-- lib/pages/itemview.dart | 6 ++++++ lib/pages/supply.dart | 11 ++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index 72bc8e4..c276010 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -141,7 +141,7 @@ class API { // /supply Future supplyItem(String item, String variant, String price, - String? origin, String? location) async { + String? origin, String? location, String? note) async { if (origin!.isEmpty) { origin = null; } @@ -150,12 +150,17 @@ class API { location = null; } + if (note!.isEmpty) { + note = null; + } + var req = await postRequest("$instance/supply", { "item": item, "variant": variant, "price": price, "origin": origin, - "location": location + "location": location, + "note": note }); var resp = jsonDecode(req); @@ -349,6 +354,7 @@ class Transaction { late int timestamp; late ConsumeInfo? consumed; late bool expired; + late String? note; Transaction(Map json) { uuid = json["uuid"]; @@ -358,6 +364,7 @@ class Transaction { origin = json["origin"]; timestamp = json["timestamp"]; expired = json["expired"]; + note = json["note"]; consumed = json["consumed"] != null ? ConsumeInfo(json["consumed"]) : null; } } diff --git a/lib/pages/itemview.dart b/lib/pages/itemview.dart index d755f8f..ed592f4 100644 --- a/lib/pages/itemview.dart +++ b/lib/pages/itemview.dart @@ -168,6 +168,12 @@ class TransactionCard extends StatelessWidget { 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), diff --git a/lib/pages/supply.dart b/lib/pages/supply.dart index 9173f21..e02ea3f 100644 --- a/lib/pages/supply.dart +++ b/lib/pages/supply.dart @@ -18,12 +18,14 @@ class _SupplyPageState extends State { String _selectedOrigin = ""; String _selectedLocation = ""; late TextEditingController _priceController; + late TextEditingController _noteController; @override void initState() { super.initState(); variant = widget.item.variants.keys.first; _priceController = TextEditingController(text: ""); + _noteController = TextEditingController(text: ""); } void _supply() { @@ -32,7 +34,7 @@ class _SupplyPageState extends State { API() .supplyItem(widget.item.name, variant, "${_priceController.text} €", - _selectedOrigin, _selectedLocation) + _selectedOrigin, _selectedLocation, _noteController.text) .then((_) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Item added successfully!')), @@ -174,6 +176,13 @@ class _SupplyPageState extends State { ], ), + // Note + TextFormField( + decoration: const InputDecoration(labelText: 'Note'), + keyboardType: TextInputType.number, + controller: _noteController, + ), + const SizedBox(height: 20), // Submit Button