123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import 'dart:math';
- import 'package:sport/bean/post_user.dart';
- import 'package:sport/services/Converter.dart';
- class Comment {
- String id;
- String subjectId;
- String userId;
- String toCommentId;
- String parentCommentId;
- String toUserId;
- String content;
- int likeCount;
- int commentCount;
- String createdAt;
- PostUser socialInfo;
- String time;
- int createTime;
- List<Comment> subList;
- bool isLiked = false;
- String userName;
- String userAvatar;
- String toUserName;
- String toUserAvatar;
- bool isExpansion;
- Comment(
- {this.id,
- this.subjectId,
- this.userId,
- this.toCommentId,
- this.parentCommentId,
- this.toUserId,
- this.content,
- this.likeCount,
- this.commentCount,
- this.createdAt,
- this.socialInfo,
- this.time,
- this.createTime,
- this.subList,
- this.isLiked = false,
- this.userName,
- this.userAvatar,
- this.toUserName,
- this.toUserAvatar,
- });
- Comment.fromJson(Map<String, dynamic> json) {
- id = json['id'];
- subjectId = json['subject_id'];
- userId = json['user_id'];
- toCommentId = json['to_comment_id'];
- parentCommentId = json['parent_comment_id'];
- toUserId = json['to_user_id'];
- content = json['content'];
- likeCount = Converter.toInt(json['like_count']);
- commentCount = Converter.toInt(json['comment_count']);
- createdAt = json['created_at'];
- socialInfo = json['socialInfo'] != null ? new PostUser.fromJson(json['socialInfo']) : null;
- time = json['time'];
- createTime = json['create_time'];
- if (json['subList'] != null) {
- subList = new List<Comment>();
- json['subList'].forEach((v) {
- subList.add(new Comment.fromJson(v));
- });
- }
- isLiked = json['is_liked'];
- userName = json['user_name'];
- userAvatar = json['user_avatar'];
- toUserName = json['to_user_name'];
- toUserAvatar = json['to_user_avatar'];
- }
- Map<String, dynamic> toJson() {
- final Map<String, dynamic> data = new Map<String, dynamic>();
- data['id'] = this.id;
- data['subject_id'] = this.subjectId;
- data['user_id'] = this.userId;
- data['to_comment_id'] = this.toCommentId;
- data['parent_comment_id'] = this.parentCommentId;
- data['to_user_id'] = this.toUserId;
- data['content'] = this.content;
- data['like_count'] = this.likeCount;
- data['comment_count'] = this.commentCount;
- data['created_at'] = this.createdAt;
- if (this.socialInfo != null) {
- data['socialInfo'] = this.socialInfo.toJson();
- }
- data['time'] = this.time;
- data['create_time'] = this.createTime;
- if (this.subList != null) {
- data['subList'] = this.subList.map((v) => v.toJson()).toList();
- }
- data['user_name'] = this.userName;
- data['user_avatar'] = this.userAvatar;
- data['to_user_name'] = this.toUserName;
- data['to_user_avatar'] = this.toUserAvatar;
- return data;
- }
- void toggleLike() {
- isLiked = !(isLiked ?? false);
- likeCount = incLikeCount();
- }
- int incLikeCount() {
- return max(0, likeCount + (isLiked ? 1 : -1));
- }
- }
|