| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- import 'package:news_app/extension/base.dart';
- class NewsDetailModel {
- String? contentId;
- String? catalogId;
- String? contentType;
- String? title;
- List<String?>? imagesSrc;
- String? author;
- String? topFlag;
- String? publishDate;
- int? likeCount;
- int? commentCount;
- int? favoriteCount;
- int? viewCount;
- String? contentHtml;
- bool? isLiked;
- bool? isFavorite;
- String? shareUrl;
- String? shareDesc;
- int? sourceType;
- NewsDetailModel({
- this.contentId,
- this.catalogId,
- this.contentType,
- this.title,
- this.imagesSrc,
- this.author,
- this.topFlag,
- this.publishDate,
- this.likeCount,
- this.commentCount,
- this.favoriteCount,
- this.viewCount,
- this.contentHtml,
- this.isLiked,
- this.isFavorite,
- this.shareUrl,
- this.shareDesc,
- this.sourceType,
- });
- NewsDetailModel.fromJson(Map<String, dynamic> json) {
- contentId = json['contentId']?.toString();
- catalogId = json['catalogId']?.toString();
- contentType = json['contentType']?.toString();
- title = json['title']?.toString();
- if (json['imagesSrc'] != null) {
- final v = json['imagesSrc'];
- final arr0 = <String>[];
- v.forEach((v) {
- arr0.add(v.toString());
- });
- imagesSrc = arr0;
- }
- author = json['author']?.toString();
- topFlag = json['topFlag']?.toString();
- publishDate = json['publishDate']?.toString();
- likeCount = json['likeCount']?.toString().convertInt;
- commentCount = json['commentCount']?.toString().convertInt;
- favoriteCount = json['favoriteCount']?.toString().convertInt;
- viewCount = json['viewCount']?.toString().convertInt;
- contentHtml = json['contentHtml']?.toString();
- isLiked = json['isLiked'];
- isFavorite = json['isFavorite'];
- shareUrl = json['shareUrl']?.toString();
- shareDesc = json['shareDesc']?.toString();
- sourceType = json['sourceType'];
- }
- Map<String, dynamic> toJson() {
- final data = <String, dynamic>{};
- data['contentId'] = contentId;
- data['catalogId'] = catalogId;
- data['contentType'] = contentType;
- data['title'] = title;
- if (imagesSrc != null) {
- final v = imagesSrc;
- final arr0 = [];
- for (var v in v!) {
- arr0.add(v);
- }
- data['imagesSrc'] = arr0;
- }
- data['author'] = author;
- data['topFlag'] = topFlag;
- data['publishDate'] = publishDate;
- data['likeCount'] = likeCount;
- data['commentCount'] = commentCount;
- data['favoriteCount'] = favoriteCount;
- data['viewCount'] = viewCount;
- data['contentHtml'] = contentHtml;
- data['isLiked'] = isLiked;
- data['isFavorite'] = isFavorite;
- data['shareUrl'] = shareUrl;
- data['shareDesc'] = shareDesc;
- data['sourceType'] = sourceType;
- return data;
- }
- //生成一个copyWith方法
- NewsDetailModel copyWith({
- String? contentId,
- String? catalogId,
- String? contentType,
- String? title,
- List<String?>? imagesSrc,
- String? author,
- String? topFlag,
- String? publishDate,
- int? likeCount,
- int? commentCount,
- int? favoriteCount,
- int? viewCount,
- String? contentHtml,
- bool? isLiked,
- bool? isFavorite,
- String? shareUrl,
- String? shareDesc,
- int? sourceType,
- }) {
- return NewsDetailModel(
- contentId: contentId ?? this.contentId,
- catalogId: catalogId ?? this.catalogId,
- contentType: contentType ?? this.contentType,
- title: title ?? this.title,
- imagesSrc: imagesSrc ?? this.imagesSrc,
- author: author ?? this.author,
- topFlag: topFlag ?? this.topFlag,
- publishDate: publishDate ?? this.publishDate,
- likeCount: likeCount ?? this.likeCount,
- commentCount: commentCount ?? this.commentCount,
- favoriteCount: favoriteCount ?? this.favoriteCount,
- viewCount: viewCount ?? this.viewCount,
- contentHtml: contentHtml ?? this.contentHtml,
- isLiked: isLiked ?? this.isLiked,
- isFavorite: isFavorite ?? this.isFavorite,
- shareUrl:shareUrl ?? this.shareUrl,
- shareDesc:shareDesc ?? this.shareDesc,
- sourceType:sourceType ?? this.sourceType,
- );
- }
- }
|