feat: update item quantity to support double values
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>master v1.1
parent
b3cb5e3e05
commit
77b3f5bb79
|
@ -1,6 +1,6 @@
|
||||||
class ReceiptItem {
|
class ReceiptItem {
|
||||||
final String description;
|
final String description;
|
||||||
final int quantity;
|
final double quantity;
|
||||||
final double price;
|
final double price;
|
||||||
|
|
||||||
ReceiptItem({
|
ReceiptItem({
|
||||||
|
@ -16,3 +16,4 @@ class ReceiptItem {
|
||||||
return 'ReceiptItem(description: $description, quantity: $quantity, price: $price)';
|
return 'ReceiptItem(description: $description, quantity: $quantity, price: $price)';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,12 @@ class _AddItemScreenState extends State<AddItemScreen> {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
// Inisialisasi controller dengan nilai default atau dari item yang diedit
|
// Inisialisasi controller dengan nilai default atau dari item yang diedit
|
||||||
_descriptionController = TextEditingController(text: widget.item?.description ?? '');
|
_descriptionController =
|
||||||
_quantityController = TextEditingController(text: widget.item != null ? widget.item!.quantity.toString() : '1');
|
TextEditingController(text: widget.item?.description ?? '');
|
||||||
_priceController = TextEditingController(text: widget.item?.price.toString() ?? '');
|
_quantityController = TextEditingController(
|
||||||
|
text: widget.item != null ? widget.item!.quantity.toString() : '1');
|
||||||
|
_priceController =
|
||||||
|
TextEditingController(text: widget.item?.price.toString() ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -41,7 +44,7 @@ class _AddItemScreenState extends State<AddItemScreen> {
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
final item = ReceiptItem(
|
final item = ReceiptItem(
|
||||||
description: _descriptionController.text,
|
description: _descriptionController.text,
|
||||||
quantity: int.parse(_quantityController.text),
|
quantity: double.parse(_quantityController.text),
|
||||||
price: double.parse(_priceController.text),
|
price: double.parse(_priceController.text),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -87,7 +90,7 @@ class _AddItemScreenState extends State<AddItemScreen> {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
return 'Mohon masukkan jumlah';
|
return 'Mohon masukkan jumlah';
|
||||||
}
|
}
|
||||||
if (int.tryParse(value) == null) {
|
if (double.tryParse(value) == null) {
|
||||||
return 'Jumlah harus berupa angka';
|
return 'Jumlah harus berupa angka';
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -133,3 +136,4 @@ class _AddItemScreenState extends State<AddItemScreen> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue