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
Future<String> 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<String, dynamic> 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;
}
}

View file

@ -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),

View file

@ -18,12 +18,14 @@ class _SupplyPageState extends State<SupplyPage> {
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<SupplyPage> {
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<SupplyPage> {
],
),
// Note
TextFormField(
decoration: const InputDecoration(labelText: 'Note'),
keyboardType: TextInputType.number,
controller: _noteController,
),
const SizedBox(height: 20),
// Submit Button