sendComment method

void sendComment(
  1. CdxCommentsLocalizations loc, {
  2. required void onInputError(
    1. String
    ),
})

Sends a comment or reply based on the current state.

Validates the content in inputController, then either:

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();
}