add notes

This commit is contained in:
JMARyA 2024-09-21 01:37:11 +02:00
parent 35977e9a61
commit 4b9e616581
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 25 additions and 3 deletions

View file

@ -141,7 +141,7 @@ class API {
// /supply // /supply
Future<String> supplyItem(String item, String variant, String price, Future<String> supplyItem(String item, String variant, String price,
String? origin, String? location) async { String? origin, String? location, String? note) async {
if (origin!.isEmpty) { if (origin!.isEmpty) {
origin = null; origin = null;
} }
@ -150,12 +150,17 @@ class API {
location = null; location = null;
} }
if (note!.isEmpty) {
note = null;
}
var req = await postRequest("$instance/supply", { var req = await postRequest("$instance/supply", {
"item": item, "item": item,
"variant": variant, "variant": variant,
"price": price, "price": price,
"origin": origin, "origin": origin,
"location": location "location": location,
"note": note
}); });
var resp = jsonDecode(req); var resp = jsonDecode(req);
@ -349,6 +354,7 @@ class Transaction {
late int timestamp; late int timestamp;
late ConsumeInfo? consumed; late ConsumeInfo? consumed;
late bool expired; late bool expired;
late String? note;
Transaction(Map<String, dynamic> json) { Transaction(Map<String, dynamic> json) {
uuid = json["uuid"]; uuid = json["uuid"];
@ -358,6 +364,7 @@ class Transaction {
origin = json["origin"]; origin = json["origin"];
timestamp = json["timestamp"]; timestamp = json["timestamp"];
expired = json["expired"]; expired = json["expired"];
note = json["note"];
consumed = json["consumed"] != null ? ConsumeInfo(json["consumed"]) : null; consumed = json["consumed"] != null ? ConsumeInfo(json["consumed"]) : null;
} }
} }

View file

@ -168,6 +168,12 @@ class TransactionCard extends StatelessWidget {
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
if ((t.note ?? "").isNotEmpty) ...[
Text(t.note!),
const SizedBox(
height: 10,
)
],
Row( Row(
children: [ children: [
const Icon(Icons.money, size: 18, color: Colors.green), const Icon(Icons.money, size: 18, color: Colors.green),

View file

@ -18,12 +18,14 @@ class _SupplyPageState extends State<SupplyPage> {
String _selectedOrigin = ""; String _selectedOrigin = "";
String _selectedLocation = ""; String _selectedLocation = "";
late TextEditingController _priceController; late TextEditingController _priceController;
late TextEditingController _noteController;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
variant = widget.item.variants.keys.first; variant = widget.item.variants.keys.first;
_priceController = TextEditingController(text: ""); _priceController = TextEditingController(text: "");
_noteController = TextEditingController(text: "");
} }
void _supply() { void _supply() {
@ -32,7 +34,7 @@ class _SupplyPageState extends State<SupplyPage> {
API() API()
.supplyItem(widget.item.name, variant, "${_priceController.text}", .supplyItem(widget.item.name, variant, "${_priceController.text}",
_selectedOrigin, _selectedLocation) _selectedOrigin, _selectedLocation, _noteController.text)
.then((_) { .then((_) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Item added successfully!')), const SnackBar(content: Text('Item added successfully!')),
@ -174,6 +176,13 @@ class _SupplyPageState extends State<SupplyPage> {
], ],
), ),
// Note
TextFormField(
decoration: const InputDecoration(labelText: 'Note'),
keyboardType: TextInputType.number,
controller: _noteController,
),
const SizedBox(height: 20), const SizedBox(height: 20),
// Submit Button // Submit Button