enum ProductCategory { food, drink, beverage } class ProductModel { final String name; final String image; final String description; final double price; String? category1; String? brandname; final ProductCategory category; final String id; int quantity; ProductModel({ required this.name, required this.image, required this.description, required this.price, required this.category, this.category1, this.brandname, required this.id, this.quantity = 1, }); // Factory constructor factory ProductModel.fromJson(Map json) { return ProductModel( name: json['name']??"", image: json['image']??"", description: json['description']??"", price: json['price']??"", category: ProductCategory.values.firstWhere((e) => e.toString().split('.').last == json['category']), category1: json['category1']??"", brandname: json['brandname']??"", id: json['id'], quantity: json['quantity'] ?? 1, ); } // Optional: toJson method if you need to convert the model back to JSON Map toJson() { return { 'name': name, 'image': image, 'description': description, 'price': price, 'category': category.toString().split('.').last, 'category1': category1, 'brandname': brandname, 'id': id, 'quantity': quantity, }; } }