|
14 | 14 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
15 | 15 |
|
16 | 16 | class Image { |
17 | | - final int id; |
18 | | - final DateTime dateCreated; |
19 | | - final DateTime dateCreatedGMT; |
20 | | - final DateTime dateModified; |
21 | | - final DateTime dateModifiedGMT; |
22 | | - final String src; |
23 | | - final String name; |
24 | | - final String alt; |
| 17 | + int id; |
| 18 | + DateTime dateCreated; |
| 19 | + DateTime dateCreatedGMT; |
| 20 | + DateTime dateModified; |
| 21 | + DateTime dateModifiedGMT; |
| 22 | + String src; |
| 23 | + String name; |
| 24 | + String alt; |
25 | 25 |
|
26 | 26 | Image(this.id, this.src, this.name, this.alt, this.dateCreated, |
27 | 27 | this.dateCreatedGMT, this.dateModified, this.dateModifiedGMT); |
28 | 28 |
|
29 | | - Image.fromJson(Map<String, dynamic> json) |
30 | | - : id = json['id'], |
31 | | - src = json['src'], |
32 | | - name = json['name'], |
33 | | - alt = json['alt'], |
34 | | - dateCreated = DateTime.parse(json['date_created']), |
35 | | - dateModifiedGMT = DateTime.parse(json['date_modified_gmt']), |
36 | | - dateModified = DateTime.parse(json['date_modified']), |
37 | | - dateCreatedGMT = DateTime.parse(json['date_created_gmt']); |
| 29 | + Image.fromJson(Map<String, dynamic> json) { |
| 30 | + id = json['id']; |
| 31 | + src = (json['src'] is String ? json['src'] : json['src'].toString()); |
| 32 | + name = json['name']; |
| 33 | + alt = json['alt']; |
| 34 | + if (json['date_created'] != null) { |
| 35 | + dateCreated = DateTime.parse(json['date_created']); |
| 36 | + } |
| 37 | + if (json['date_modified_gmt'] != null) { |
| 38 | + dateModifiedGMT = DateTime.parse(json['date_modified_gmt']); |
| 39 | + } |
| 40 | + if (json['date_modified'] != null) { |
| 41 | + dateModified = DateTime.parse(json['date_modified']); |
| 42 | + } |
| 43 | + if (json['date_created_gmt'] != null) { |
| 44 | + dateCreatedGMT = DateTime.parse(json['date_created_gmt']); |
| 45 | + } |
| 46 | + } |
38 | 47 |
|
39 | 48 | Map<String, dynamic> toJson() => { |
40 | 49 | 'id': this.id, |
|
0 commit comments