abhi_diablo

CategoryItemModel class

Oct 8th, 2020
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.98 KB | None | 0 0
  1. import 'dart:convert';
  2. CategoryItemModel categoryItemModelFromJson(String str) => CategoryItemModel.fromJson(json.decode(str));
  3.  
  4. String categoryItemModelToJson(CategoryItemModel data) => json.encode(data.toJson());
  5. class CategoryItemModel {
  6.   CategoryItemModel({
  7.     this.success,
  8.     this.message,
  9.     this.data,
  10.   });
  11.  
  12.   bool success;
  13.   String message;
  14.   Data data;
  15.  
  16.   factory CategoryItemModel.fromJson(Map<String, dynamic> json) => CategoryItemModel(
  17.     success: json["success"],
  18.     message: json["message"],
  19.     data: Data.fromJson(json["data"]),
  20.   );
  21.  
  22.   Map<String, dynamic> toJson() => {
  23.     "success": success,
  24.     "message": message,
  25.     "data": data.toJson(),
  26.   };
  27. }
  28.  
  29. class Data {
  30.   Data({
  31.     this.customTags,
  32.     this.userTags,
  33.   });
  34.  
  35.   List<CustomTag> customTags;
  36.   List<Tag> userTags;
  37.  
  38.   factory Data.fromJson(Map<String, dynamic> json) => Data(
  39.     customTags: List<CustomTag>.from(json["custom_tags"].map((x) => CustomTag.fromJson(x))),
  40.     userTags: List<Tag>.from(json["user_tags"].map((x) => Tag.fromJson(x))),
  41.   );
  42.  
  43.   Map<String, dynamic> toJson() => {
  44.     "custom_tags": List<dynamic>.from(customTags.map((x) => x.toJson())),
  45.     "user_tags": List<dynamic>.from(userTags.map((x) => x.toJson())),
  46.   };
  47. }
  48.  
  49. class CustomTag {
  50.   CustomTag({
  51.     this.id,
  52.     this.userId,
  53.     this.name,
  54.     this.deletedAt,
  55.     this.createdAt,
  56.     this.updatedAt,
  57.   });
  58.  
  59.   int id;
  60.   int userId;
  61.   String name;
  62.   dynamic deletedAt;
  63.   DateTime createdAt;
  64.   DateTime updatedAt;
  65.  
  66.   factory CustomTag.fromJson(Map<String, dynamic> json) => CustomTag(
  67.     id: json["id"],
  68.     userId: json["user_id"],
  69.     name: json["name"],
  70.     deletedAt: json["deleted_at"],
  71.     createdAt: DateTime.parse(json["created_at"]),
  72.     updatedAt: DateTime.parse(json["updated_at"]),
  73.   );
  74.  
  75.   Map<String, dynamic> toJson() => {
  76.     "id": id,
  77.     "user_id": userId,
  78.     "name": name,
  79.     "deleted_at": deletedAt,
  80.     "created_at": createdAt.toIso8601String(),
  81.     "updated_at": updatedAt.toIso8601String(),
  82.   };
  83. }
  84.  
  85. class Tag {
  86.   Tag({
  87.     this.id,
  88.     this.name,
  89.     this.slug,
  90.     this.icon,
  91.     this.thumbs,
  92.     this.createdAt,
  93.     this.updatedAt,
  94.     this.tags,
  95.     this.translated,
  96.     this.tagCategoryId,
  97.     this.flyerItemsCount,
  98.   });
  99.  
  100.   int id;
  101.   String name;
  102.   String slug;
  103.   String icon;
  104.   Thumbs thumbs;
  105.   DateTime createdAt;
  106.   DateTime updatedAt;
  107.   List<Tag> tags;
  108.   dynamic translated;
  109.   int tagCategoryId;
  110.   int flyerItemsCount;
  111.  
  112.   factory Tag.fromJson(Map<String, dynamic> json) => Tag(
  113.     id: json["id"],
  114.     name: json["name"],
  115.     slug: json["slug"],
  116.     icon: json["icon"],
  117.     thumbs: Thumbs.fromJson(json["thumbs"]),
  118.     createdAt: DateTime.parse(json["created_at"]),
  119.     updatedAt: DateTime.parse(json["updated_at"]),
  120.     tags: json["tags"] == null ? null : List<Tag>.from(json["tags"].map((x) => Tag.fromJson(x))),
  121.     translated: json["translated"],
  122.     tagCategoryId: json["tag_category_id"] == null ? null : json["tag_category_id"],
  123.     flyerItemsCount: json["flyer_items_count"] == null ? null : json["flyer_items_count"],
  124.   );
  125.  
  126.   Map<String, dynamic> toJson() => {
  127.     "id": id,
  128.     "name": name,
  129.     "slug": slug,
  130.     "icon": icon,
  131.     "thumbs": thumbs.toJson(),
  132.     "created_at": createdAt.toIso8601String(),
  133.     "updated_at": updatedAt.toIso8601String(),
  134.     "tags": tags == null ? null : List<dynamic>.from(tags.map((x) => x.toJson())),
  135.     "translated": translated,
  136.     "tag_category_id": tagCategoryId == null ? null : tagCategoryId,
  137.     "flyer_items_count": flyerItemsCount == null ? null : flyerItemsCount,
  138.   };
  139. }
  140.  
  141. class Thumbs {
  142.   Thumbs({
  143.     this.lg,
  144.     this.md,
  145.     this.sm,
  146.     this.xs,
  147.   });
  148.  
  149.   String lg;
  150.   String md;
  151.   String sm;
  152.   String xs;
  153.  
  154.   factory Thumbs.fromJson(Map<String, dynamic> json) => Thumbs(
  155.     lg: json["lg"],
  156.     md: json["md"],
  157.     sm: json["sm"],
  158.     xs: json["xs"],
  159.   );
  160.  
  161.   Map<String, dynamic> toJson() => {
  162.     "lg": lg,
  163.     "md": md,
  164.     "sm": sm,
  165.     "xs": xs,
  166.   };
  167. }
  168.  
Advertisement
Add Comment
Please, Sign In to add comment