Skip to content

Instantly share code, notes, and snippets.

@Sanwal13
Created October 17, 2020 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sanwal13/f6af0e376d168e398ac11e43af49be7d to your computer and use it in GitHub Desktop.
Save Sanwal13/f6af0e376d168e398ac11e43af49be7d to your computer and use it in GitHub Desktop.
// To parse this JSON data, do
//
// final home = homeFromJson(jsonString);
import 'dart:convert';
Home homeFromJson(String str) => Home.fromJson(json.decode(str));
String homeToJson(Home data) => json.encode(data.toJson());
class Home {
Home({
this.advImg,
this.infoText,
this.shopCat,
this.section,
this.storeImg,
});
List<AdvImg> advImg;
List<InfoText> infoText;
List<ShopCat> shopCat;
List<Section> section;
String storeImg;
factory Home.fromJson(Map<String, dynamic> json) => Home(
advImg: List<AdvImg>.from(json["adv_img"].map((x) => AdvImg.fromJson(x))),
infoText: List<InfoText>.from(json["info_text"].map((x) => InfoText.fromJson(x))),
shopCat: List<ShopCat>.from(json["shop_cat"].map((x) => ShopCat.fromJson(x))),
section: List<Section>.from(json["section"].map((x) => Section.fromJson(x))),
storeImg: json["store_img"],
);
Map<String, dynamic> toJson() => {
"adv_img": List<dynamic>.from(advImg.map((x) => x.toJson())),
"info_text": List<dynamic>.from(infoText.map((x) => x.toJson())),
"shop_cat": List<dynamic>.from(shopCat.map((x) => x.toJson())),
"section": List<dynamic>.from(section.map((x) => x.toJson())),
"store_img": storeImg,
};
}
class AdvImg {
AdvImg({
this.categoryId,
this.image,
this.tag,
});
String categoryId;
String image;
String tag;
factory AdvImg.fromJson(Map<String, dynamic> json) => AdvImg(
categoryId: json["category_id"],
image: json["image"],
tag: json["tag"],
);
Map<String, dynamic> toJson() => {
"category_id": categoryId,
"image": image,
"tag": tag,
};
}
class InfoText {
InfoText({
this.textHead,
this.textSub,
});
String textHead;
String textSub;
factory InfoText.fromJson(Map<String, dynamic> json) => InfoText(
textHead: json["text_head"],
textSub: json["text_sub"],
);
Map<String, dynamic> toJson() => {
"text_head": textHead,
"text_sub": textSub,
};
}
class Section {
Section({
this.banner,
this.topSelling,
this.shopBy,
});
List<Banner> banner;
TopSelling topSelling;
ShopBy shopBy;
factory Section.fromJson(Map<String, dynamic> json) => Section(
banner: List<Banner>.from(json["banner"].map((x) => Banner.fromJson(x))),
topSelling: TopSelling.fromJson(json["top_selling"]),
shopBy: ShopBy.fromJson(json["shop_by"]),
);
Map<String, dynamic> toJson() => {
"banner": List<dynamic>.from(banner.map((x) => x.toJson())),
"top_selling": topSelling.toJson(),
"shop_by": shopBy.toJson(),
};
}
class Banner {
Banner({
this.tag,
this.categoryId,
this.categoryName,
this.bannerImage,
this.screen,
});
String tag;
String categoryId;
String categoryName;
String bannerImage;
int screen;
factory Banner.fromJson(Map<String, dynamic> json) => Banner(
tag: json["tag"],
categoryId: json["category_id"],
categoryName: json["category_name"],
bannerImage: json["banner_image"],
screen: json["screen"] == null ? null : json["screen"],
);
Map<String, dynamic> toJson() => {
"tag": tag,
"category_id": categoryId,
"category_name": categoryName,
"banner_image": bannerImage,
"screen": screen == null ? null : screen,
};
}
class ShopBy {
ShopBy({
this.tag,
this.viewType,
this.traget,
this.data,
});
String tag;
int viewType;
int traget;
List<List<Datum>> data;
factory ShopBy.fromJson(Map<String, dynamic> json) => ShopBy(
tag: json["tag"],
viewType: json["view_type"],
traget: json["traget"],
data: List<List<Datum>>.from(json["data"].map((x) => List<Datum>.from(x.map((x) => Datum.fromJson(x))))),
);
Map<String, dynamic> toJson() => {
"tag": tag,
"view_type": viewType,
"traget": traget,
"data": List<dynamic>.from(data.map((x) => List<dynamic>.from(x.map((x) => x.toJson())))),
};
}
class Datum {
Datum({
this.productId,
this.categoryId,
this.name,
this.image,
this.price,
this.special,
this.discount,
this.fabricConcept,
});
String productId;
String categoryId;
String name;
String image;
String price;
String special;
Discount discount;
String fabricConcept;
factory Datum.fromJson(Map<String, dynamic> json) => Datum(
productId: json["product_id"],
categoryId: json["category_id"],
name: json["name"],
image: json["image"],
price: json["price"],
special: json["special"],
discount: discountValues.map[json["discount"]],
fabricConcept: json["fabricConcept"],
);
Map<String, dynamic> toJson() => {
"product_id": productId,
"category_id": categoryId,
"name": name,
"image": image,
"price": price,
"special": special,
"discount": discountValues.reverse[discount],
"fabricConcept": fabricConcept,
};
}
enum Discount { EMPTY, NULL }
final discountValues = EnumValues({
"": Discount.EMPTY,
"null": Discount.NULL
});
class TopSelling {
TopSelling({
this.tag,
this.viewType,
this.traget,
this.data,
});
String tag;
int viewType;
int traget;
List<Datum> data;
factory TopSelling.fromJson(Map<String, dynamic> json) => TopSelling(
tag: json["tag"],
viewType: json["view_type"],
traget: json["traget"],
data: List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"tag": tag,
"view_type": viewType,
"traget": traget,
"data": List<dynamic>.from(data.map((x) => x.toJson())),
};
}
class ShopCat {
ShopCat({
this.categoryId,
this.iconImage,
this.categoryName,
});
String categoryId;
String iconImage;
String categoryName;
factory ShopCat.fromJson(Map<String, dynamic> json) => ShopCat(
categoryId: json["category_id"],
iconImage: json["icon_image"],
categoryName: json["category_name"],
);
Map<String, dynamic> toJson() => {
"category_id": categoryId,
"icon_image": iconImage,
"category_name": categoryName,
};
}
class EnumValues<T> {
Map<String, T> map;
Map<T, String> reverseMap;
EnumValues(this.map);
Map<T, String> get reverse {
if (reverseMap == null) {
reverseMap = map.map((k, v) => new MapEntry(v, k));
}
return reverseMap;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment