| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- 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<TopicRecordModel>? 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<TopicRecordModel>? 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<String, dynamic> json) {
- return TopicItemModel(
- records:
- (json['records'] as List<dynamic>)
- .map((e) => TopicRecordModel.fromJson(e as Map<String, dynamic>))
- .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<Resource>? resourceList;
- final List<dynamic>? 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<String, dynamic> json) {
- return TopicRecordModel(
- member: Member.fromJson(json['member']),
- contentId: json['contentId'] ?? '',
- content: json['content'] ?? '',
- resourceList:
- (json['resourceList'] as List<dynamic>)
- .map((e) => Resource.fromJson(e as Map<String, dynamic>))
- .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<Resource>? resourceList,
- List<dynamic>? 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> json) {
- return Resource(type: json['type'] ?? '', url: json['url'] ?? '');
- }
- }
|