news_data_model.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. import 'package:news_app/extension/base.dart';
  2. class NewsDataModel {
  3. NewsDataModel({
  4. List<NewsRecord>? records,
  5. int? total,
  6. int? size,
  7. int? current,
  8. int? pages,
  9. }) {
  10. _records = records;
  11. _total = total;
  12. _size = size;
  13. _current = current;
  14. _pages = pages;
  15. }
  16. NewsDataModel.fromJson(dynamic json) {
  17. if (json['records'] != null) {
  18. _records = [];
  19. json['records'].forEach((v) {
  20. _records?.add(NewsRecord.fromJson(v));
  21. });
  22. }
  23. _total = json['total'].toString().convertInt;
  24. _size = json['size'].toString().convertInt;
  25. _current = json['current'].toString().convertInt;
  26. _pages = json['pages'].toString().convertInt;
  27. }
  28. List<NewsRecord>? _records;
  29. int? _total;
  30. int? _size;
  31. int? _current;
  32. int? _pages;
  33. NewsDataModel copyWith({
  34. List<NewsRecord>? records,
  35. int? total,
  36. int? size,
  37. int? current,
  38. int? pages,
  39. }) => NewsDataModel(
  40. records: records ?? _records,
  41. total: total ?? _total,
  42. size: size ?? _size,
  43. current: current ?? _current,
  44. pages: pages ?? _pages,
  45. );
  46. List<NewsRecord>? get records => _records;
  47. int? get total => _total;
  48. int? get size => _size;
  49. int? get current => _current;
  50. int? get pages => _pages;
  51. Map<String, dynamic> toJson() {
  52. final map = <String, dynamic>{};
  53. if (_records != null) {
  54. map['records'] = _records?.map((v) => v.toJson()).toList();
  55. }
  56. map['total'] = _total;
  57. map['size'] = _size;
  58. map['current'] = _current;
  59. map['pages'] = _pages;
  60. return map;
  61. }
  62. }
  63. class NewsRecord {
  64. NewsRecord({
  65. String? contentId,
  66. String? catalogId,
  67. String? contentType,
  68. String? title,
  69. String? logo,
  70. List<String>? images,
  71. List<String>? imagesSrc,
  72. String? author,
  73. String? editor,
  74. String? summary,
  75. List<String>? attributes,
  76. String? topFlag,
  77. List<String>? keywords,
  78. List<String>? tags,
  79. String? publishDateStr,
  80. String? likeCount,
  81. String? commentCount,
  82. String? favoriteCount,
  83. String? viewCount,
  84. bool? isLiked,
  85. bool? isFavorite,
  86. }) {
  87. _contentId = contentId;
  88. _catalogId = catalogId;
  89. _contentType = contentType;
  90. _title = title;
  91. _logo = logo;
  92. _images = images;
  93. _imagesSrc = imagesSrc;
  94. _author = author;
  95. _editor = editor;
  96. _summary = summary;
  97. _attributes = attributes;
  98. _topFlag = topFlag;
  99. _keywords = keywords;
  100. _tags = tags;
  101. _publishDateStr = publishDateStr;
  102. _likeCount = likeCount;
  103. _commentCount = commentCount;
  104. _favoriteCount = favoriteCount;
  105. _viewCount = viewCount;
  106. _isLiked = isLiked;
  107. _isFavorite = isFavorite;
  108. }
  109. NewsRecord.fromJson(dynamic json) {
  110. _contentId = json['contentId'];
  111. _catalogId = json['catalogId'];
  112. _contentType = json['contentType'];
  113. _title = json['title'];
  114. _logo = json['logo'];
  115. _images = json['images'] != null ? json['images'].cast<String>() : [];
  116. _imagesSrc =
  117. json['imagesSrc'] != null ? json['imagesSrc'].cast<String>() : [];
  118. _author = json['author'];
  119. _editor = json['editor'];
  120. _summary = json['summary'];
  121. _attributes =
  122. json['attributes'] != null ? json['attributes'].cast<String>() : [];
  123. _topFlag = json['topFlag'];
  124. _keywords = json['keywords'] != null ? json['keywords'].cast<String>() : [];
  125. _tags = json['tags'] != null ? json['tags'].cast<String>() : [];
  126. _publishDateStr = json['publishDateStr'];
  127. _likeCount = json['likeCount'];
  128. _commentCount = json['commentCount'];
  129. _favoriteCount = json['favoriteCount'];
  130. _viewCount = json['viewCount'];
  131. _isLiked = json['isLiked'];
  132. _isFavorite = json['isFavorite'];
  133. }
  134. String? _contentId;
  135. String? _catalogId;
  136. String? _contentType;
  137. String? _title;
  138. String? _logo;
  139. List<String>? _images;
  140. List<String>? _imagesSrc;
  141. String? _author;
  142. String? _editor;
  143. String? _summary;
  144. List<String>? _attributes;
  145. String? _topFlag;
  146. List<String>? _keywords;
  147. List<String>? _tags;
  148. String? _publishDateStr;
  149. String? _likeCount;
  150. String? _commentCount;
  151. String? _favoriteCount;
  152. String? _viewCount;
  153. bool? _isLiked;
  154. bool? _isFavorite;
  155. NewsRecord copyWith({
  156. String? contentId,
  157. String? catalogId,
  158. String? contentType,
  159. String? title,
  160. String? logo,
  161. List<String>? images,
  162. List<String>? imagesSrc,
  163. String? author,
  164. String? editor,
  165. String? summary,
  166. List<String>? attributes,
  167. String? topFlag,
  168. List<String>? keywords,
  169. List<String>? tags,
  170. String? publishDateStr,
  171. String? likeCount,
  172. String? commentCount,
  173. String? favoriteCount,
  174. String? viewCount,
  175. bool? isLiked,
  176. bool? isFavorite,
  177. }) => NewsRecord(
  178. contentId: contentId ?? _contentId,
  179. catalogId: catalogId ?? _catalogId,
  180. contentType: contentType ?? _contentType,
  181. title: title ?? _title,
  182. logo: logo ?? _logo,
  183. images: images ?? _images,
  184. imagesSrc: imagesSrc ?? _imagesSrc,
  185. author: author ?? _author,
  186. editor: editor ?? _editor,
  187. summary: summary ?? _summary,
  188. attributes: attributes ?? _attributes,
  189. topFlag: topFlag ?? _topFlag,
  190. keywords: keywords ?? _keywords,
  191. tags: tags ?? _tags,
  192. publishDateStr: publishDateStr ?? _publishDateStr,
  193. likeCount: likeCount ?? _likeCount,
  194. commentCount: commentCount ?? _commentCount,
  195. favoriteCount: favoriteCount ?? _favoriteCount,
  196. viewCount: viewCount ?? _viewCount,
  197. isLiked: isLiked ?? _isLiked,
  198. isFavorite: isFavorite ?? _isFavorite,
  199. );
  200. String? get contentId => _contentId;
  201. String? get catalogId => _catalogId;
  202. String? get contentType => _contentType;
  203. String? get title => _title;
  204. String? get logo => _logo;
  205. List<String>? get images => _images;
  206. List<String>? get imagesSrc => _imagesSrc;
  207. String? get author => _author;
  208. String? get editor => _editor;
  209. String? get summary => _summary;
  210. List<String>? get attributes => _attributes;
  211. String? get topFlag => _topFlag;
  212. List<String>? get keywords => _keywords;
  213. List<String>? get tags => _tags;
  214. String? get publishDateStr => _publishDateStr;
  215. String? get likeCount => _likeCount;
  216. String? get commentCount => _commentCount;
  217. String? get favoriteCount => _favoriteCount;
  218. String? get viewCount => _viewCount;
  219. bool? get isLiked => _isLiked;
  220. bool? get isFavorite => _isFavorite;
  221. Map<String, dynamic> toJson() {
  222. final map = <String, dynamic>{};
  223. map['contentId'] = _contentId;
  224. map['catalogId'] = _catalogId;
  225. map['contentType'] = _contentType;
  226. map['title'] = _title;
  227. map['logo'] = _logo;
  228. map['images'] = _images;
  229. map['imagesSrc'] = _imagesSrc;
  230. map['author'] = _author;
  231. map['editor'] = _editor;
  232. map['summary'] = _summary;
  233. map['attributes'] = _attributes;
  234. map['topFlag'] = _topFlag;
  235. if (_keywords != null) {
  236. map['keywords'] = _keywords;
  237. }
  238. map['tags'] = _tags;
  239. map['publishDateStr'] = _publishDateStr;
  240. map['likeCount'] = _likeCount;
  241. map['commentCount'] = _commentCount;
  242. map['favoriteCount'] = _favoriteCount;
  243. map['viewCount'] = _viewCount;
  244. map['isLiked'] = _isLiked;
  245. map['isFavorite'] = _isFavorite;
  246. return map;
  247. }
  248. }