feat: update item quantity to support double values

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
master v1.1
a2nr 2025-09-18 11:39:03 +07:00
parent b3cb5e3e05
commit 77b3f5bb79
2 changed files with 16 additions and 11 deletions

View File

@ -1,6 +1,6 @@
class ReceiptItem {
final String description;
final int quantity;
final double quantity;
final double price;
ReceiptItem({
@ -16,3 +16,4 @@ class ReceiptItem {
return 'ReceiptItem(description: $description, quantity: $quantity, price: $price)';
}
}

View File

@ -24,9 +24,12 @@ class _AddItemScreenState extends State<AddItemScreen> {
super.initState();
// Inisialisasi controller dengan nilai default atau dari item yang diedit
_descriptionController = TextEditingController(text: widget.item?.description ?? '');
_quantityController = TextEditingController(text: widget.item != null ? widget.item!.quantity.toString() : '1');
_priceController = TextEditingController(text: widget.item?.price.toString() ?? '');
_descriptionController =
TextEditingController(text: widget.item?.description ?? '');
_quantityController = TextEditingController(
text: widget.item != null ? widget.item!.quantity.toString() : '1');
_priceController =
TextEditingController(text: widget.item?.price.toString() ?? '');
}
@override
@ -41,7 +44,7 @@ class _AddItemScreenState extends State<AddItemScreen> {
if (_formKey.currentState!.validate()) {
final item = ReceiptItem(
description: _descriptionController.text,
quantity: int.parse(_quantityController.text),
quantity: double.parse(_quantityController.text),
price: double.parse(_priceController.text),
);
@ -87,7 +90,7 @@ class _AddItemScreenState extends State<AddItemScreen> {
if (value == null || value.isEmpty) {
return 'Mohon masukkan jumlah';
}
if (int.tryParse(value) == null) {
if (double.tryParse(value) == null) {
return 'Jumlah harus berupa angka';
}
return null;
@ -133,3 +136,4 @@ class _AddItemScreenState extends State<AddItemScreen> {
);
}
}