Untitled
unknown
plain_text
3 years ago
7.5 kB
11
Indexable
class ProductsModel {
ProductsModel({
this.code,
this.status,
this.message,
this.data,
});
int? code;
bool? status;
String? message;
List<Datum>? data;
factory ProductsModel.fromJson(Map<String, dynamic> json) => ProductsModel(
code: json["code"],
status: json["status"],
message: json["message"],
data: List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"code": code,
"status": status,
"message": message,
"data": List<dynamic>.from(data!.map((x) => x.toJson())),
};
}
class Datum {
Datum({
this.id,
this.userId,
this.productName,
this.brandId,
this.categoryId,
this.subcategoryId,
this.size,
this.color,
this.price,
this.discountRate,
this.quantity,
this.discountPrice,
this.discription,
this.image,
this.slug,
this.sku,
this.credit,
this.totalPrice,
this.featureProduct,
this.trandProduct,
this.exclusiveProduct,
this.rate,
this.status,
this.createdAt,
this.updatedAt,
this.productToCategory,
this.productToSubcategory,
this.productToBrand,
this.galleryProduct,
});
int? id;
String? userId;
String? productName;
String? brandId;
String? categoryId;
String? subcategoryId;
List<Size>? size;
List<String>? color;
String? price;
String? discountRate;
String? quantity;
String? discountPrice;
String? discription;
String? image;
String? slug;
String? sku;
Credit? credit;
String? totalPrice;
String? featureProduct;
String? trandProduct;
String? exclusiveProduct;
String? rate;
Status? status;
DateTime? createdAt;
DateTime? updatedAt;
ProductTo? productToCategory;
ProductTo? productToSubcategory;
ProductTo? productToBrand;
GalleryProduct? galleryProduct;
factory Datum.fromJson(Map<String, dynamic> json) => Datum(
id: json["id"],
userId: json["user_id"],
productName: json["product_name"],
brandId: json["brand_id"],
categoryId: json["category_id"],
subcategoryId: json["subcategory_id"],
size: List<Size>.from(json["size"].map((x) => sizeValues.map![x])),
color: List<String>.from(json["color"].map((x) => x)),
price: json["price"],
discountRate: json["discount_rate"],
quantity: json["quantity"],
discountPrice: json["discount_price"],
discription: json["discription"],
image: json["image"],
slug: json["slug"],
sku: json["sku"],
credit: creditValues.map![json["credit"]],
totalPrice: json["total_price"],
featureProduct: json["feature_product"],
trandProduct: json["trand_product"],
exclusiveProduct: json["exclusive_product"],
rate: json["rate"],
status: statusValues.map![json["status"]],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: json["updated_at"] == null
? null
: DateTime.parse(json["updated_at"]),
productToCategory: ProductTo.fromJson(json["product_to_category"]),
productToSubcategory:
ProductTo.fromJson(json["product_to_subcategory"]),
productToBrand: ProductTo.fromJson(json["product_to_brand"]),
galleryProduct: GalleryProduct.fromJson(json["gallery_product"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"user_id": userId,
"product_name": productName,
"brand_id": brandId,
"category_id": categoryId,
"subcategory_id": subcategoryId,
"size": List<dynamic>.from(size!.map((x) => sizeValues.reverse[x])),
"color": List<dynamic>.from(color!.map((x) => x)),
"price": price,
"discount_rate": discountRate,
"quantity": quantity,
"discount_price": discountPrice,
"discription": discription,
"image": image,
"slug": slug,
"sku": sku,
"credit": creditValues.reverse[credit],
"total_price": totalPrice,
"feature_product": featureProduct,
"trand_product": trandProduct,
"exclusive_product": exclusiveProduct,
"rate": rate,
"status": statusValues.reverse[status],
"created_at": createdAt!.toIso8601String(),
"updated_at": updatedAt == null ? null : updatedAt!.toIso8601String(),
"product_to_category": productToCategory!.toJson(),
"product_to_subcategory": productToSubcategory!.toJson(),
"product_to_brand": productToBrand!.toJson(),
"gallery_product": galleryProduct!.toJson(),
};
}
enum Credit { EMPTY, CREDIT }
final creditValues = EnumValues({"%": Credit.CREDIT, "-": Credit.EMPTY});
class GalleryProduct {
GalleryProduct({
this.id,
this.productId,
this.image,
this.image1,
this.image2,
this.image3,
this.createdAt,
this.updatedAt,
});
int? id;
String? productId;
String? image;
String? image1;
String? image2;
String? image3;
dynamic? createdAt;
DateTime? updatedAt;
factory GalleryProduct.fromJson(Map<String, dynamic> json) => GalleryProduct(
id: json["id"],
productId: json["product_id"],
image: json["image"],
image1: json["image1"],
image2: json["image2"],
image3: json["image3"],
createdAt: json["created_at"],
updatedAt: json["updated_at"] == null
? null
: DateTime.parse(json["updated_at"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"product_id": productId,
"image": image,
"image1": image1,
"image2": image2,
"image3": image3,
"created_at": createdAt,
"updated_at": updatedAt == null ? null : updatedAt!.toIso8601String(),
};
}
class ProductTo {
ProductTo({
this.id,
this.brandTitle,
this.photo,
this.summary,
this.status,
this.createdAt,
this.updatedAt,
this.title,
this.categoryId,
});
int? id;
String? brandTitle;
String? photo;
dynamic summary;
Status? status;
DateTime? createdAt;
DateTime? updatedAt;
String? title;
String? categoryId;
factory ProductTo.fromJson(Map<String, dynamic> json) => ProductTo(
id: json["id"],
brandTitle: json["brand_title"],
photo: json["photo"],
summary: json["summary"],
status: statusValues.map![json["status"]],
createdAt: DateTime.parse(json["created_at"]),
updatedAt: DateTime.parse(json["updated_at"]),
title: json["title"],
categoryId: json["category_id"],
);
Map<String, dynamic> toJson() => {
"id": id,
"brand_title": brandTitle,
"photo": photo,
"summary": summary,
"status": statusValues.reverse[status],
"created_at": createdAt!.toIso8601String(),
"updated_at": updatedAt!.toIso8601String(),
"title": title,
"category_id": categoryId,
};
}
enum Status { INACTIVE, ACTIVE }
final statusValues =
EnumValues({"active": Status.ACTIVE, "inactive": Status.INACTIVE});
enum Size { S, M, L, XXL }
final sizeValues =
EnumValues({"L": Size.L, "M": Size.M, "S": Size.S, "XXL": Size.XXL});
class EnumValues<T> {
Map<String, T>? map;
Map<T, String>? reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
reverseMap ??= map!.map((k, v) => MapEntry(v, k));
return reverseMap!;
}
}
Editor is loading...