-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy patharticle_model.dart
More file actions
91 lines (83 loc) · 2.22 KB
/
article_model.dart
File metadata and controls
91 lines (83 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class Article {
Article({
required this.status,
required this.totalResults,
required this.articles,
});
late final String status;
late final int totalResults;
late final List<Articles> articles;
Article.fromJson(Map<String, dynamic> json) {
status = json['status'];
totalResults = json['totalResults'];
articles =
List.from(json['articles']).map((e) => Articles.fromJson(e)).toList();
}
Map<String, dynamic> toJson() {
final _data = <String, dynamic>{};
_data['status'] = status;
_data['totalResults'] = totalResults;
_data['articles'] = articles.map((e) => e.toJson()).toList();
return _data;
}
}
class Articles {
Articles({
required this.source,
this.author,
required this.title,
this.description,
required this.url,
required this.urlToImage,
required this.publishedAt,
this.content,
});
late final Source source;
late final String? author;
late final String? title;
late final String? description;
late final String? url;
late final String? urlToImage;
late final String? publishedAt;
late final String? content;
Articles.fromJson(Map<String, dynamic> json) {
source = Source.fromJson(json['source']);
author = null;
title = json['title'];
description = json['description'];
url = json['url'];
urlToImage = json['urlToImage'];
publishedAt = json['publishedAt'];
content = null;
}
Map<String, dynamic> toJson() {
final _data = <String, dynamic>{};
_data['source'] = source.toJson();
_data['author'] = author;
_data['title'] = title;
_data['description'] = description;
_data['url'] = url;
_data['urlToImage'] = urlToImage;
_data['publishedAt'] = publishedAt;
_data['content'] = content;
return _data;
}
}
class Source {
Source({
this.id,
required this.name,
});
late final String? id;
late final String name;
Source.fromJson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
}
Map<String, dynamic> toJson() {
final _data = <String, dynamic>{};
_data['id'] = id;
_data['name'] = name;
return _data;
}
}