class Product { int id; String title; String description; double price; double discountPercentage; double rating; double stock; String brand; String category; String thumbnail; List images; Product({ required this.id, required this.title, required this.description, required this.price, required this.discountPercentage, required this.rating, required this.stock, required this.brand, required this.category, required this.thumbnail, required this.images, }); Product.fromJson(Map json) : id = json['id'], title = json['title'], description = json['description'], price = json['price'].toDouble(), discountPercentage = json['discountPercentage'].toDouble(), rating = json['rating'].toDouble(), stock = json['stock'].toDouble(), brand = json['brand'], category = json['category'], thumbnail = json['thumbnail'], images = json['images'].cast(); Map toJson() { final Map data = { 'id': id, 'title': title, 'description': description, 'price': price, 'discountPercentage': discountPercentage, 'rating': rating, 'stock': stock, 'brand': brand, 'category': category, 'thumbnail': thumbnail, 'images': images, }; return data; } } class PagedProducts { List products; int total; int skip; int limit; PagedProducts({ this.products = const [], required this.total, required this.skip, required this.limit, }); PagedProducts.fromJson(Map json) : products = json['products'] ?.map((v) => Product.fromJson( Map.castFrom(v), )) .toList() ?? [], total = json['total'], skip = json['skip'], limit = json['limit']; Map toJson() { final Map data = { 'products': products.map((v) => v.toJson()).toList(), 'total': total, 'skip': skip, 'limit': limit, }; return data; } }