copyWith method

Comment copyWith({
  1. String? id,
  2. DateTime? date,
  3. String? parentId,
  4. String? content,
  5. String? entityId,
  6. String? userId,
  7. String? username,
  8. int? likeCount,
  9. int? replyCount,
  10. bool? isLiked,
  11. bool? isMine,
  12. List<Comment>? replies,
})

Creates a copy of this comment with the given fields replaced.

All parameters are optional. If a parameter is not provided, the value from this comment is used.

Returns a new Comment instance with updated values.

Example:

final updated = comment.copyWith(
  likeCount: comment.likeCount! + 1,
  isLiked: true,
);

Implementation

Comment copyWith({
  String? id,
  DateTime? date,
  String? parentId,
  String? content,
  String? entityId,
  String? userId,
  String? username,
  int? likeCount,
  int? replyCount,
  bool? isLiked,
  bool? isMine,
  List<Comment>? replies,
}) {
  return Comment(
    id: id ?? this.id,
    date: date ?? this.date,
    parentId: parentId ?? this.parentId,
    content: content ?? this.content,
    entityId: entityId ?? this.entityId,
    userId: userId ?? this.userId,
    username: username ?? this.username,
    likeCount: likeCount ?? this.likeCount,
    replyCount: replyCount ?? this.replyCount,
    isLiked: isLiked ?? this.isLiked,
    isMine: isMine ?? this.isMine,
    replies: replies ?? this.replies,
  );
}