submitComment function
Implementation
Future<String?> submitComment(
L10n lang,
String plainDescription,
String htmlBodyDescription,
CommentsManager manager,
) async {
final trimmedPlainText = plainDescription.trim();
if (trimmedPlainText.isEmpty) {
EasyLoading.showToast(lang.youNeedToEnterAComment);
return null;
}
EasyLoading.show(status: lang.submittingComment);
try {
final draft = manager.commentDraft();
draft.contentFormatted(trimmedPlainText, htmlBodyDescription);
final id = await draft.send();
FocusManager.instance.primaryFocus?.unfocus();
EasyLoading.showToast(lang.commentSubmitted);
return id.toString();
} catch (e, s) {
_log.severe('Failed to submit comment', e, s);
EasyLoading.showError(
lang.errorSubmittingComment(e),
duration: const Duration(seconds: 3),
);
return null;
}
}