special_model.dart 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import 'package:news_app/extension/base.dart';
  2. class SpecialModel {
  3. SpecialModel({
  4. List<SpecialRecord>? 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. SpecialModel.fromJson(dynamic json) {
  17. if (json['records'] != null) {
  18. _records = [];
  19. json['records'].forEach((v) {
  20. _records?.add(SpecialRecord.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<SpecialRecord>? _records;
  29. int? _total;
  30. int? _size;
  31. int? _current;
  32. int? _pages;
  33. SpecialModel copyWith({
  34. List<SpecialRecord>? records,
  35. int? total,
  36. int? size,
  37. int? current,
  38. int? pages,
  39. }) => SpecialModel(
  40. records: records ?? _records,
  41. total: total ?? _total,
  42. size: size ?? _size,
  43. current: current ?? _current,
  44. pages: pages ?? _pages,
  45. );
  46. List<SpecialRecord>? 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 SpecialRecord {
  64. SpecialRecord({
  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. // List<dynamic>? attributes,
  74. String? topFlag,
  75. String? publishDate,
  76. String? likeCount,
  77. String? commentCount,
  78. String? favoriteCount,
  79. String? viewCount,
  80. bool? isLiked,
  81. bool? isFavorite,
  82. }) {
  83. _contentId = contentId;
  84. _catalogId = catalogId;
  85. _contentType = contentType;
  86. _title = title;
  87. _logo = logo;
  88. _images = images;
  89. _imagesSrc = imagesSrc;
  90. _author = author;
  91. //_attributes = attributes;
  92. _topFlag = topFlag;
  93. _publishDate = publishDate;
  94. _likeCount = likeCount;
  95. _commentCount = commentCount;
  96. _favoriteCount = favoriteCount;
  97. _viewCount = viewCount;
  98. _isLiked = isLiked;
  99. _isFavorite = isFavorite;
  100. }
  101. SpecialRecord.fromJson(dynamic json) {
  102. _contentId = json['contentId'];
  103. _catalogId = json['catalogId'];
  104. _contentType = json['contentType'];
  105. _title = json['title'];
  106. _logo = json['logo'];
  107. _images = json['images'] != null ? json['images'].cast<String>() : [];
  108. _imagesSrc =
  109. json['imagesSrc'] != null ? json['imagesSrc'].cast<String>() : [];
  110. _author = json['author'];
  111. /* if (json['attributes'] != null) {
  112. _attributes = [];
  113. json['attributes'].forEach((v) {
  114. _attributes?.add(Dynamic.fromJson(v));
  115. });
  116. }*/
  117. _topFlag = json['topFlag'];
  118. _publishDate = json['publishDate'];
  119. _likeCount = json['likeCount'];
  120. _commentCount = json['commentCount'];
  121. _favoriteCount = json['favoriteCount'];
  122. _viewCount = json['viewCount'];
  123. _isLiked = json['isLiked'];
  124. _isFavorite = json['isFavorite'];
  125. }
  126. String? _contentId;
  127. String? _catalogId;
  128. String? _contentType;
  129. String? _title;
  130. String? _logo;
  131. List<String>? _images;
  132. List<String>? _imagesSrc;
  133. String? _author;
  134. //List<dynamic>? _attributes;
  135. String? _topFlag;
  136. String? _publishDate;
  137. String? _likeCount;
  138. String? _commentCount;
  139. String? _favoriteCount;
  140. String? _viewCount;
  141. bool? _isLiked;
  142. bool? _isFavorite;
  143. SpecialRecord copyWith({
  144. String? contentId,
  145. String? catalogId,
  146. String? contentType,
  147. String? title,
  148. String? logo,
  149. List<String>? images,
  150. List<String>? imagesSrc,
  151. String? author,
  152. // List<dynamic>? attributes,
  153. String? topFlag,
  154. String? publishDate,
  155. String? likeCount,
  156. String? commentCount,
  157. String? favoriteCount,
  158. String? viewCount,
  159. bool? isLiked,
  160. bool? isFavorite,
  161. }) => SpecialRecord(
  162. contentId: contentId ?? _contentId,
  163. catalogId: catalogId ?? _catalogId,
  164. contentType: contentType ?? _contentType,
  165. title: title ?? _title,
  166. logo: logo ?? _logo,
  167. images: images ?? _images,
  168. imagesSrc: imagesSrc ?? _imagesSrc,
  169. author: author ?? _author,
  170. //attributes: attributes ?? _attributes,
  171. topFlag: topFlag ?? _topFlag,
  172. publishDate: publishDate ?? _publishDate,
  173. likeCount: likeCount ?? _likeCount,
  174. commentCount: commentCount ?? _commentCount,
  175. favoriteCount: favoriteCount ?? _favoriteCount,
  176. viewCount: viewCount ?? _viewCount,
  177. isLiked: isLiked ?? _isLiked,
  178. isFavorite: isFavorite ?? _isFavorite,
  179. );
  180. String? get contentId => _contentId;
  181. String? get catalogId => _catalogId;
  182. String? get contentType => _contentType;
  183. String? get title => _title;
  184. String? get logo => _logo;
  185. List<String>? get images => _images;
  186. List<String>? get imagesSrc => _imagesSrc;
  187. String? get author => _author;
  188. //List<dynamic>? get attributes => _attributes;
  189. String? get topFlag => _topFlag;
  190. String? get publishDate => _publishDate;
  191. String? get likeCount => _likeCount;
  192. String? get commentCount => _commentCount;
  193. String? get favoriteCount => _favoriteCount;
  194. String? get viewCount => _viewCount;
  195. bool? get isLiked => _isLiked;
  196. bool? get isFavorite => _isFavorite;
  197. Map<String, dynamic> toJson() {
  198. final map = <String, dynamic>{};
  199. map['contentId'] = _contentId;
  200. map['catalogId'] = _catalogId;
  201. map['contentType'] = _contentType;
  202. map['title'] = _title;
  203. map['logo'] = _logo;
  204. map['images'] = _images;
  205. map['imagesSrc'] = _imagesSrc;
  206. map['author'] = _author;
  207. /* if (_attributes != null) {
  208. map['attributes'] = _attributes?.map((v) => v.toJson()).toList();
  209. }*/
  210. map['topFlag'] = _topFlag;
  211. map['publishDate'] = _publishDate;
  212. map['likeCount'] = _likeCount;
  213. map['commentCount'] = _commentCount;
  214. map['favoriteCount'] = _favoriteCount;
  215. map['viewCount'] = _viewCount;
  216. map['isLiked'] = _isLiked;
  217. map['isFavorite'] = _isFavorite;
  218. return map;
  219. }
  220. }