news_detail_model.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import 'package:news_app/extension/base.dart';
  2. class NewsDetailModel {
  3. String? contentId;
  4. String? catalogId;
  5. String? contentType;
  6. String? title;
  7. List<String?>? imagesSrc;
  8. String? author;
  9. String? topFlag;
  10. String? publishDate;
  11. int? likeCount;
  12. int? commentCount;
  13. int? favoriteCount;
  14. int? viewCount;
  15. String? contentHtml;
  16. bool? isLiked;
  17. bool? isFavorite;
  18. String? shareUrl;
  19. String? shareDesc;
  20. int? sourceType;
  21. NewsDetailModel({
  22. this.contentId,
  23. this.catalogId,
  24. this.contentType,
  25. this.title,
  26. this.imagesSrc,
  27. this.author,
  28. this.topFlag,
  29. this.publishDate,
  30. this.likeCount,
  31. this.commentCount,
  32. this.favoriteCount,
  33. this.viewCount,
  34. this.contentHtml,
  35. this.isLiked,
  36. this.isFavorite,
  37. this.shareUrl,
  38. this.shareDesc,
  39. this.sourceType,
  40. });
  41. NewsDetailModel.fromJson(Map<String, dynamic> json) {
  42. contentId = json['contentId']?.toString();
  43. catalogId = json['catalogId']?.toString();
  44. contentType = json['contentType']?.toString();
  45. title = json['title']?.toString();
  46. if (json['imagesSrc'] != null) {
  47. final v = json['imagesSrc'];
  48. final arr0 = <String>[];
  49. v.forEach((v) {
  50. arr0.add(v.toString());
  51. });
  52. imagesSrc = arr0;
  53. }
  54. author = json['author']?.toString();
  55. topFlag = json['topFlag']?.toString();
  56. publishDate = json['publishDate']?.toString();
  57. likeCount = json['likeCount']?.toString().convertInt;
  58. commentCount = json['commentCount']?.toString().convertInt;
  59. favoriteCount = json['favoriteCount']?.toString().convertInt;
  60. viewCount = json['viewCount']?.toString().convertInt;
  61. contentHtml = json['contentHtml']?.toString();
  62. isLiked = json['isLiked'];
  63. isFavorite = json['isFavorite'];
  64. shareUrl = json['shareUrl']?.toString();
  65. shareDesc = json['shareDesc']?.toString();
  66. sourceType = json['sourceType'];
  67. }
  68. Map<String, dynamic> toJson() {
  69. final data = <String, dynamic>{};
  70. data['contentId'] = contentId;
  71. data['catalogId'] = catalogId;
  72. data['contentType'] = contentType;
  73. data['title'] = title;
  74. if (imagesSrc != null) {
  75. final v = imagesSrc;
  76. final arr0 = [];
  77. for (var v in v!) {
  78. arr0.add(v);
  79. }
  80. data['imagesSrc'] = arr0;
  81. }
  82. data['author'] = author;
  83. data['topFlag'] = topFlag;
  84. data['publishDate'] = publishDate;
  85. data['likeCount'] = likeCount;
  86. data['commentCount'] = commentCount;
  87. data['favoriteCount'] = favoriteCount;
  88. data['viewCount'] = viewCount;
  89. data['contentHtml'] = contentHtml;
  90. data['isLiked'] = isLiked;
  91. data['isFavorite'] = isFavorite;
  92. data['shareUrl'] = shareUrl;
  93. data['shareDesc'] = shareDesc;
  94. data['sourceType'] = sourceType;
  95. return data;
  96. }
  97. //生成一个copyWith方法
  98. NewsDetailModel copyWith({
  99. String? contentId,
  100. String? catalogId,
  101. String? contentType,
  102. String? title,
  103. List<String?>? imagesSrc,
  104. String? author,
  105. String? topFlag,
  106. String? publishDate,
  107. int? likeCount,
  108. int? commentCount,
  109. int? favoriteCount,
  110. int? viewCount,
  111. String? contentHtml,
  112. bool? isLiked,
  113. bool? isFavorite,
  114. String? shareUrl,
  115. String? shareDesc,
  116. int? sourceType,
  117. }) {
  118. return NewsDetailModel(
  119. contentId: contentId ?? this.contentId,
  120. catalogId: catalogId ?? this.catalogId,
  121. contentType: contentType ?? this.contentType,
  122. title: title ?? this.title,
  123. imagesSrc: imagesSrc ?? this.imagesSrc,
  124. author: author ?? this.author,
  125. topFlag: topFlag ?? this.topFlag,
  126. publishDate: publishDate ?? this.publishDate,
  127. likeCount: likeCount ?? this.likeCount,
  128. commentCount: commentCount ?? this.commentCount,
  129. favoriteCount: favoriteCount ?? this.favoriteCount,
  130. viewCount: viewCount ?? this.viewCount,
  131. contentHtml: contentHtml ?? this.contentHtml,
  132. isLiked: isLiked ?? this.isLiked,
  133. isFavorite: isFavorite ?? this.isFavorite,
  134. shareUrl:shareUrl ?? this.shareUrl,
  135. shareDesc:shareDesc ?? this.shareDesc,
  136. sourceType:sourceType ?? this.sourceType,
  137. );
  138. }
  139. }