Comment class
Represents a comment with support for nested replies.
A comment can be either a root comment (top-level) or a reply to another comment.
Root comments have parentId set to null, while replies have it set to the parent's ID.
Example:
final comment = Comment(
id: 'comment-1',
date: DateTime.now(),
content: 'This is a comment',
entityId: 'post-123',
userId: 'user-1',
username: 'John Doe',
likeCount: 5,
isLiked: false,
);
Constructors
-
Comment({required String id, required DateTime date, String? parentId, required String content, required String entityId, required String userId, required String username, int? likeCount, int? replyCount, bool? isLiked, bool isMine = false, List<
Comment> replies = const []}) - Creates a new Comment.
-
Comment.fromJson(Map<
String, dynamic> json, {required String? currentUserId, List<Comment> ? replies}) -
Creates a Comment from a JSON map.
factory
Properties
- content → String
-
The text content of the comment.
final
- date → DateTime
-
Date and time when the comment was created.
final
- entityId → String
-
ID of the entity (post, article, etc.) this comment belongs to.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
Unique identifier for this comment.
final
- initials → String
-
Gets the initials for the comment author.
no setter
- isLiked → bool?
-
Whether the current user has liked this comment.
final
- isMine → bool
-
Whether this comment was created by the current user.
final
- isRoot → bool
-
Whether this is a root comment (not a reply).
no setter
- likeCount → int?
-
Number of likes this comment has received.
final
- parentId → String?
-
ID of the parent comment, if this is a reply.
final
-
replies
→ List<
Comment> -
List of direct replies to this comment.
final
- replyCount ↔ int?
-
Number of replies this comment has.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- userId → String
-
ID of the user who created this comment.
final
- username → String
-
Display name of the user who created this comment.
final
Methods
-
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}) → Comment - Creates a copy of this comment with the given fields replaced.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, String> - Converts this comment to a JSON map.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited