import 'package:news_app/extension/base.dart'; class NewsDetailModel { String? contentId; String? catalogId; String? contentType; String? title; List? 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 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 = []; 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 toJson() { final data = {}; 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? 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, ); } }