sendComment method
Sends a comment or reply based on the current state.
Validates the content in inputController, then either:
- Adds a new comment if replyingTo is
null - Adds a reply if replyingTo is not
null
After sending, clears the input field and resets replyingTo if it was set.
loc is the CdxCommentsLocalizations instance for error messages.
onInputError is a callback that will be called with an error message
if validation fails.
If the input is empty, this method returns without doing anything.
Implementation
void sendComment(CdxCommentsLocalizations loc, {required void Function(String) onInputError}) async {
final text = inputController.text.trim();
if (text.isEmpty) return;
final error = await validator.validate(text, loc);
if (error != null) {
onInputError(error);
return;
}
if (replyingTo != null) {
replyTo(
postId,
replyingTo!.id,
text,
);
setReplyTo(null);
} else {
addComment(text);
}
inputController.clear();
}