-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy patharticle_model.dart
More file actions
99 lines (81 loc) · 2.66 KB
/
article_model.dart
File metadata and controls
99 lines (81 loc) · 2.66 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
92
93
94
95
96
97
98
99
// To parse this JSON data, do
//
// final welcome = welcomeFromJson(jsonString);
import 'dart:convert';
Welcome welcomeFromJson(String str) => Welcome.fromJson(json.decode(str));
String welcomeToJson(Welcome data) => json.encode(data.toJson());
class Welcome {
Welcome({
required this.status,
required this.totalResults,
required this.articles,
});
final String status;
final int totalResults;
final List<Article> articles;
factory Welcome.fromJson(Map<String, dynamic> json) => Welcome(
status: json["status"],
totalResults: json["totalResults"],
articles: List<Article>.from(json["articles"].map((x) => Article.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"status": status,
"totalResults": totalResults,
"articles": List<dynamic>.from(articles.map((x) => x.toJson())),
};
}
class Article {
Article({
//required this.author,
required this.title,
required this.description,
required this.url,
required this.urlToImage,
//required this.publishedAt,
//required this.content,
});
//final Source source;
//final String author;
final String title;
final String description;
final String url;
final String urlToImage;
// final DateTime publishedAt;
//final String content;
factory Article.fromJson(Map<String, dynamic> json) => Article(
// source: Source.fromJson(json["source"]),
// author: json["author"] == null ? null : json["author"],
title: json["title"] as String,
description: json["description"] as String,
url: json["url"] as String,
urlToImage: json["urlToImage"] as String,
// publishedAt: DateTime.parse(json["publishedAt"]),
//content: json["content"] == null ? null : json["content"],
);
Map<String, dynamic> toJson() => {
//"source": source.toJson(),
//"author": author == null ? null : author,
"title": title,
"description": description,
"url": url,
"urlToImage": urlToImage as String?,
// "publishedAt": publishedAt.toIso8601String(),
//"content": content == null ? null : content,
};
}
// class Source {
// Source({
// required this.id,
// required this.name,
// });
// final String id;
// final String name;
// factory Source.fromJson(Map<String, dynamic> json) => Source(
// id: json["id"] == null ? null : json["id"],
// name: json["name"],
// );
// Map<String, dynamic> toJson() => {
// "id": id == null ? null : id,
// "name": name,
// };
// }