// models/product_model.dart
class ProductModel {
final int id;
final String title;
final double price;
// ...
factory ProductModel.fromJson(Map<String, dynamic> json) {
return ProductModel(
id: (json['id'] as num).toInt(),
title: json['title'] as String,
price: (json['price'] as num).toDouble(),
// other fields...
rating: RatingModel.fromJson(json['rating'] as Map<String, dynamic>),
);
}
}
class RatingModel {
final double rate;
final int count;
factory RatingModel.fromJson(Map<String, dynamic> json) {
return RatingModel(
rate: (json['rate'] as num).toDouble(),
count: (json['count'] as num).toInt(),
);
}
}