74 lines
1.5 KiB
Dart
74 lines
1.5 KiB
Dart
class Brand {
|
|
final String id;
|
|
final String brandName;
|
|
List<BrandImage> images;
|
|
|
|
Brand({
|
|
required this.id,
|
|
required this.brandName,
|
|
required this.images,
|
|
});
|
|
|
|
factory Brand.fromJson(Map<String, dynamic> json) {
|
|
return Brand(
|
|
id: json['_id'],
|
|
brandName: json['brandName'],
|
|
// images: json["image"] != null
|
|
// ? (json["image"] as List).map((e) => BrandImage.fromJson(e)).toList()
|
|
// : [],
|
|
images: json["image"] != null // Ensure you use the correct key
|
|
? (json["image"] as List)
|
|
.map((e) => BrandImage.fromJson(e))
|
|
.toList()
|
|
: [],
|
|
|
|
);
|
|
}
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'_id': id,
|
|
'brandName': brandName,
|
|
"image": images.map((e) => e.toJson()).toList(),
|
|
|
|
};
|
|
}
|
|
@override
|
|
String toString() {
|
|
return 'Brand(id: $id, brandName: $brandName,images: $images)';
|
|
}
|
|
}
|
|
|
|
|
|
|
|
class BrandImage {
|
|
String publicId;
|
|
String url;
|
|
String imageId;
|
|
|
|
BrandImage({
|
|
required this.publicId,
|
|
required this.url,
|
|
required this.imageId,
|
|
});
|
|
|
|
factory BrandImage.fromJson(Map<String, dynamic> json) {
|
|
return BrandImage(
|
|
publicId: json["public_id"] ?? "",
|
|
url: json["url"]?.toString() ?? "",
|
|
imageId: json["_id"] ?? "",
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
"public_id": publicId,
|
|
"url": url,
|
|
"_id": imageId,
|
|
};
|
|
}
|
|
|
|
@override
|
|
String toString() {
|
|
return "BrandImage(publicId: $publicId, url: $url, imageId: $imageId)";
|
|
}
|
|
} |