class ProductHomePageModel { final List banners; final List categories; final List featured; final List latest; ProductHomePageModel({ required this.banners, required this.categories, required this.featured, required this.latest, }); factory ProductHomePageModel.fromJson(Map json) { return ProductHomePageModel( banners: (json['banners'] is List) ? (json['banners'] as List) .map((e) => BannerModel.fromJson(e)) .toList() : [], categories: (json['categories'] is List) ? (json['categories'] as List) .map((e) => CategoryModel.fromJson(e)) .toList() : [], featured: (json['featured_products'] is List) ? (json['featured_products'] as List) .map((e) => ProductModel.fromJson(e)) .toList() : [], latest: (json['latest_products'] is List) ? (json['latest_products'] as List) .map((e) => ProductModel.fromJson(e)) .toList() : [], ); } Map toJson() => { 'banners': banners.map((e) => e.toJson()).toList(), 'categories': categories.map((e) => e.toJson()).toList(), 'featured_products': featured.map((e) => e.toJson()).toList(), 'latest_products': latest.map((e) => e.toJson()).toList(), }; } /// Banner Model class BannerModel { final int id; final String image; BannerModel({required this.id, required this.image}); factory BannerModel.fromJson(Map json) { return BannerModel( id: json['id'] ?? 0, image: (json['image'] is String) ? json['image'] : '', ); } Map toJson() => {'id': id, 'image': image}; } /// Category Model class CategoryModel { final int id; final String name; final String slug; final String? image; // can be null/false CategoryModel({ required this.id, required this.name, required this.slug, this.image, }); factory CategoryModel.fromJson(Map json) { return CategoryModel( id: json['id'] ?? 0, name: (json['name'] is String) ? json['name'] : '', slug: (json['slug'] is String) ? json['slug'] : '', image: (json['image'] is String) ? json['image'] : null, ); } Map toJson() => { 'id': id, 'name': name, 'slug': slug, 'image': image, }; } /// Product Model (for featured & latest) class ProductModel { final int id; final String name; final String price; final String image; ProductModel({ required this.id, required this.name, required this.price, required this.image, }); factory ProductModel.fromJson(Map json) { return ProductModel( id: json['id'] ?? 0, name: (json['name'] is String) ? json['name'] : '', price: (json['price'] is String) ? json['price'] : '', image: (json['image'] is String) ? json['image'] : '', ); } Map toJson() => { 'id': id, 'name': name, 'price': price, 'image': image, }; }