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 {
 | 
			
		||||
  final String description;
 | 
			
		||||
  final int quantity;
 | 
			
		||||
  final double quantity;
 | 
			
		||||
  final double price;
 | 
			
		||||
 | 
			
		||||
  ReceiptItem({
 | 
			
		||||
| 
						 | 
				
			
			@ -15,4 +15,5 @@ class ReceiptItem {
 | 
			
		|||
  String toString() {
 | 
			
		||||
    return 'ReceiptItem(description: $description, quantity: $quantity, price: $price)';
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@ import 'package:cashumit/models/receipt_item.dart';
 | 
			
		|||
 | 
			
		||||
class AddItemScreen extends StatefulWidget {
 | 
			
		||||
  const AddItemScreen({super.key, this.item});
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  // Constructor untuk mode edit
 | 
			
		||||
  const AddItemScreen.fromItem(this.item, {super.key});
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -22,11 +22,14 @@ class _AddItemScreenState extends State<AddItemScreen> {
 | 
			
		|||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    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,10 +44,10 @@ 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),
 | 
			
		||||
      );
 | 
			
		||||
      
 | 
			
		||||
 | 
			
		||||
      Navigator.pop(context, item);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			@ -132,4 +135,5 @@ class _AddItemScreenState extends State<AddItemScreen> {
 | 
			
		|||
      ],
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue