rd-android-app/lib/models/product_model.dart
saritabirare 215877afc4 1)Order Place api Integration
2)Confirm Order api Integration
3)get Oder api Integration
2024-09-06 14:39:40 +05:30

56 lines
1.4 KiB
Dart

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<String, dynamic> 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<String, dynamic> toJson() {
return {
'name': name,
'image': image,
'description': description,
'price': price,
'category': category.toString().split('.').last,
'category1': category1,
'brandname': brandname,
'id': id,
'quantity': quantity,
};
}
}