CommentProvider class
Provider for managing comment state and UI interactions.
This class manages the state of comments for a specific entity (post). It handles loading, adding, replying, liking, and deleting comments, and notifies listeners when the state changes.
Example:
final provider = CommentProvider(
controller: commentController,
postId: 'post-123',
validator: commentValidator,
);
- Mixed-in types
Constructors
- CommentProvider({required CommentController controller, required String postId, required CommentValidator validator})
- Creates a new CommentProvider.
Properties
-
comments
→ List<
Comment> -
The list of comments for this entity.
no setter
- controller → CommentController
-
The controller for comment operations.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- inputController → TextEditingController
-
Text editing controller for the comment input field.
final
- postId → String
-
The ID of the entity (post) this provider manages comments for.
final
- replyingTo → Comment?
-
The comment that the user is currently replying to.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- validator → CommentValidator
-
Validator for comment content.
final
Methods
-
addComment(
String content) → Future< void> - Adds a new comment to the entity.
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
deleteComment(
String commentId) → Future< void> - Deletes a comment from the list.
-
deleteReply(
String parentId, String replyId) → Future< void> - Deletes a reply from a parent comment.
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
inherited
-
expandReplies(
String commentId) → Future< void> -
loadComments(
) → Future< void> - Loads comments for the entity.
-
loadMoreReplies(
String commentId) → Future< void> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
replyTo(
String entityId, String parentId, String content) → Future< void> - Adds a reply to a comment.
-
sendComment(
CdxCommentsLocalizations loc, {required void onInputError(String)}) → void - Sends a comment or reply based on the current state.
-
setReplyTo(
Comment? comment) → void - Sets the comment to reply to.
-
toggleLike(
String commentId) → Future< void> - Toggles the like status of a comment.
-
toggleReplyLike(
String parentId, String replyId) → Future< void> - Toggles the like status of a reply.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited