creatImagePost method
Implementation
Future<void> creatImagePost(BuildContext context,
{String? communityId}) async {
log("creatImagePost...");
List<AmityImage> images = [];
for (var amityImage in amityImages) {
if (amityImage.fileInfo is AmityImage) {
var image = amityImage.fileInfo as AmityImage;
images.add(image);
log("add file to _images");
}
}
log(images.toString());
bool isCommunity = (communityId != null) ? true : false;
if (isCommunity) {
await AmitySocialClient.newPostRepository()
.createPost()
.targetCommunity(communityId)
.image(images)
.text(textEditingController.text)
.post()
.then((AmityPost post) {
///add post to feedx
Provider.of<CommuFeedVM>(context, listen: false).addPostToFeed(post);
Provider.of<CommuFeedVM>(context, listen: false)
.scrollcontroller
.jumpTo(0);
}).onError((error, stackTrace) async {
log(error.toString());
await AmityDialog()
.showAlertErrorDialog(title: "Error!", message: error.toString());
});
} else {
await AmitySocialClient.newPostRepository()
.createPost()
.targetMe()
.image(images)
.text(textEditingController.text)
.post()
.then((AmityPost post) {
///add post to feedx
Provider.of<FeedVM>(context, listen: false).addPostToFeed(post);
Provider.of<FeedVM>(context, listen: false).scrollcontroller.jumpTo(0);
}).onError((error, stackTrace) async {
log(error.toString());
await AmityDialog()
.showAlertErrorDialog(title: "Error!", message: error.toString());
});
}
}