class Product { final String id; final String name; final String barcode; final double price; final double priceReseller; final int stock; final int minStock; final double hargaPokok; Product({ required this.id, required this.name, this.barcode = '', required this.price, this.priceReseller = 0, required this.stock, this.minStock = 5, this.hargaPokok = 0, }); factory Product.fromJson(Map json) { return Product( id: json['id'] as String, name: json['name'] as String, barcode: json['barcode'] != null ? json['barcode'] as String : '', price: (json['price'] as num).toDouble(), priceReseller: json['price_reseller'] != null ? (json['price_reseller'] as num).toDouble() : 0, stock: json['stock'] as int, minStock: json['min_stock'] != null ? (json['min_stock'] as int) : 5, hargaPokok: json['harga_pokok'] != null ? (json['harga_pokok'] as num).toDouble() : 0, ); } Map toJson() => { 'id': id, 'name': name, 'barcode': barcode, 'price': price, 'price_reseller': priceReseller, 'stock': stock, 'min_stock': minStock, 'harga_pokok': hargaPokok, }; }