79666089

Date: 2025-06-14 19:13:34
Score: 0.5
Natty:
Report link
// 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(),
    );
  }
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: محمود ريحانية