createPost method
Implementation
Future<void> createPost(String communityId) async {
final token = await CommunityStorage.getAuthToken();
if (_titleController.text.isEmpty || _contentController.text.isEmpty) {
Get.snackbar('Error', CommunityMessages.errorGeneric);
return;
}
if (token == null) {
Get.snackbar('Error', CommunityMessages.loginRequired);
return;
}
try {
isLoading.value = true;
requireSmartLinksNativeBridge();
final result = await SmartLinksNativeApi.createPost(
communityId: communityId,
title: _titleController.text,
content: _contentController.text,
authToken: token,
);
if (result != null) {
Get.snackbar('Success', CommunityMessages.commentAdded);
_titleController.clear();
_contentController.clear();
Get.back(result: true);
} else {
Get.snackbar('Error', CommunityMessages.errorGeneric);
}
} catch (e) {
Get.snackbar('Error', CommunityMessages.errorGeneric);
} finally {
isLoading.value = false;
}
}