Advertisement
multiarts

ProductsModel

Dec 27th, 2019
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.13 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. class ProductsModel {
  4.   String id;
  5.   String title;
  6.   String description;
  7.   double price;
  8.   bool active;
  9.   bool destaque;
  10.   String thumb;
  11.   List<Images> images = [];
  12.   List<Adcionais> adcionais = [];
  13.   Category category;
  14.   Color color;
  15.  
  16.   ProductsModel(
  17.       {this.id,
  18.       this.title,
  19.       this.description,
  20.       this.price,
  21.       this.active,
  22.       this.destaque,
  23.       this.thumb,
  24.       this.images,
  25.       this.adcionais,
  26.       this.category,
  27.       this.color});
  28.  
  29.   ProductsModel.fromJson(Map<String, dynamic> json) {
  30.     id = json['id'] as String;
  31.     title = json['title'] as String;
  32.     description = json['description'] as String;
  33.     price = json['price'];
  34.     active = json['active'];
  35.     destaque = json['destaque'];
  36.     thumb = json['thumb'];
  37.     if (json['images'] != null) {
  38.       images = List<Images>();
  39.       json['images'].forEach((v) {
  40.         images.add(Images.fromJson(v));
  41.       });
  42.     }
  43.     if (json['adcionais'] != null) {
  44.       adcionais = List<Adcionais>();
  45.       json['adcionais'].forEach((v) {
  46.         adcionais.add(Adcionais.fromJson(v));
  47.       });
  48.     }
  49.     category =
  50.         json['category'] != null ? Category.fromJson(json['category']) : null;
  51.     color = json['color'];
  52.   }
  53.  
  54.   Map<String, dynamic> toJson() {
  55.     final Map<String, dynamic> data = Map<String, dynamic>();
  56.     data['id'] = this.id;
  57.     data['title'] = this.title;
  58.     data['description'] = this.description;
  59.     data['price'] = this.price;
  60.     data['active'] = this.active;
  61.     data['destaque'] = this.destaque;
  62.     data['thumb'] = this.thumb;
  63.     data['color'] = this.color;
  64.     if (this.images != null) {
  65.       data['images'] = this.images.map((v) => v.toJson()).toList();
  66.     }
  67.     if (this.adcionais != null) {
  68.       data['adcionais'] = this.adcionais.map((v) => v.toJson()).toList();
  69.     }
  70.     if (this.category != null) {
  71.       data['category'] = this.category.toJson();
  72.     }
  73.     return data;
  74.   }
  75. }
  76.  
  77. class Images {
  78.   String url;
  79.  
  80.   Images({this.url});
  81.  
  82.   Images.fromJson(Map<String, dynamic> json) {
  83.     url = json['url'];
  84.   }
  85.  
  86.   Map<String, dynamic> toJson() {
  87.     final Map<String, dynamic> data = Map<String, dynamic>();
  88.     data['url'] = this.url;
  89.     return data;
  90.   }
  91. }
  92.  
  93. class Adcionais {
  94.   String id;
  95.   String title;
  96.   double price;
  97.  
  98.   Adcionais({this.id, this.title, this.price});
  99.  
  100.   Adcionais.fromJson(Map<String, dynamic> json) {
  101.     id = json['id'] as String;
  102.     title = json['title'] as String;
  103.     price = json['price'];
  104.   }
  105.  
  106.   Map<String, dynamic> toJson() {
  107.     final Map<String, dynamic> data = Map<String, dynamic>();
  108.     data['id'] = this.id;
  109.     data['title'] = this.title;
  110.     data['price'] = this.price;
  111.     return data;
  112.   }
  113. }
  114.  
  115. class Category {
  116.   String id;
  117.   String title;
  118.  
  119.   Category({this.title});
  120.  
  121.   Category.fromJson(Map<String, dynamic> json) {
  122.     id = json['id'] as String;
  123.     title = json['title'] as String;
  124.   }
  125.  
  126.   Map<String, dynamic> toJson() {
  127.     final Map<String, dynamic> data = Map<String, dynamic>();
  128.     data['id'] = this.id;
  129.     data['title'] = this.title;
  130.     return data;
  131.   }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement