import 'package:news_app/extension/base.dart'; /// @author: bo.zeng /// @email: cnhbwds@gmail.com /// @date: 2025 2025/4/9 16:00 /// @description: class TopicItemModel { final List? records; final int? total; final int? size; final int? current; final int? pages; TopicItemModel({ this.records, this.total, this.size, this.current, this.pages, }); TopicItemModel copyWith({ int? total, int? size, int? current, int? pages, List? records, }) { return TopicItemModel( total: total ?? this.total, size: size ?? this.size, current: current ?? this.current, pages: pages ?? this.pages, records: records ?? this.records, ); } factory TopicItemModel.fromJson(Map json) { return TopicItemModel( records: (json['records'] as List) .map((e) => TopicRecordModel.fromJson(e as Map)) .toList(), total: json['total'].toString().convertInt, size: json['size'].toString().convertInt, current: json['current'].toString().convertInt, pages: json['pages'].toString().convertInt, ); } } class TopicRecordModel { final Member? member; final String? contentId; final String? content; final List? resourceList; final List? commentList; // 可以根据实际再建模型 final int? likeNum; final int? commentNum; final Topic? topic; bool? isLiked; bool? isFavorite; int? favoriteCount; final String? shareUrl; final String? shareDesc; TopicRecordModel({ this.member, this.contentId, this.content, this.resourceList, this.commentList, this.likeNum, this.commentNum, this.topic, this.isLiked, this.isFavorite, this.favoriteCount, this.shareUrl, this.shareDesc, }); factory TopicRecordModel.fromJson(Map json) { return TopicRecordModel( member: Member.fromJson(json['member']), contentId: json['contentId'] ?? '', content: json['content'] ?? '', resourceList: (json['resourceList'] as List) .map((e) => Resource.fromJson(e as Map)) .toList(), commentList: json['commentList'] ?? [], likeNum: json['likeNum'].toString().convertInt, commentNum: json['commentNum'].toString().convertInt, topic: Topic.fromJson(json['topic']), isLiked: json['isLiked'] ?? false, isFavorite: json['isFavorite'] ?? false, favoriteCount: json['favoriteCount'].toString().convertInt, shareUrl: json['shareUrl'] ?? '', shareDesc: json['shareDesc'] ?? '' ); } //生成copyWith方法 TopicRecordModel copyWith({ Member? member, String? contentId, String? content, List? resourceList, List? commentList, int? likeNum, int? commentNum, Topic? topic, bool? isLiked, bool? isFavorite, int? favoriteCount, String? shareUrl, String? shareDesc, }){ return TopicRecordModel( member: member ?? this.member, contentId: contentId ?? this.contentId, content: content ?? this.content, resourceList: resourceList ?? this.resourceList, commentList: commentList ?? this.commentList, likeNum: likeNum ?? this.likeNum, commentNum: commentNum ?? this.commentNum, topic: topic ?? this.topic, isLiked: isLiked ?? this.isLiked, isFavorite: isFavorite ?? this.isFavorite, favoriteCount: favoriteCount ?? this.favoriteCount, shareUrl:shareUrl ?? this.shareUrl, shareDesc:shareDesc ?? this.shareDesc, ); } } class Member { String? memberId; String? avatar; String? nickname; Member({this.memberId, this.avatar, this.nickname}); factory Member.fromJson(Map json) { return Member( memberId: json['memberId'] ?? '', avatar: json['avatar'] ?? '', nickname: json['nickname'] ?? '', ); } } class Topic { final String content; final String contentId; Topic({required this.content, required this.contentId}); factory Topic.fromJson(Map json) { return Topic( content: json['content'] ?? '', contentId: json['contentId'] ?? '', ); } } class Resource { final String type; final String url; Resource({required this.type, required this.url}); factory Resource.fromJson(Map json) { return Resource(type: json['type'] ?? '', url: json['url'] ?? ''); } }