Building a social media app with AWS Amplify and Flutter(PART 4)

I love creating and writing about the creation of software.
Search for a command to run...

I love creating and writing about the creation of software.
Great series of posts, thanks! I missed the part about the types of social networks, where you can choose a suitable example for yourself. Do you have a similar article about how to make a social media app ? Attached is an example article.
This series outlines the steps involved in build an MVP for a social Medial Application using the Amplify Framework and flutter
Dear Reader, when I began learning how to create mobile applications, all I ever wanted to build was the next Facebook. And deep down within, I 100% believed I could create the next big social media app that'll go head-on with Facebook😅. The yea...
Watch the complete Video on Youtube https://www.youtube.com/watch?v=kKX-8L_R2XM Prerequisites Before proceeding make sure you have these dependencies Docker Python 3.11 and above AWS CLI Full access to a foundation model. For this workshop, we'll...

Introduction In a previous workshop, Building event-driven applications with AWS sam and python we built an e-commerce ordering service using AWS SAM, API Gateway, Lambda and Python. Here's the solutions architecture. In that workshop, whenever a ne...

Github Repository https://github.com/EducloudHQ/introduction_to_gen_ai Skill up with serverless on Educloud https://www.educloud.academy/content/da99ad07-7efa-41e7-ba50-b18e6b89e10d This post is an introductory lesson to building AI-enhanced serverle...

Introduction Serverless computing is a cloud-based approach to application development that eliminates the need for provisioning and managing servers. Instead, developers focus on writing code that is triggered by events such as HTTP requests or data...

https://github.com/trey-rosius/sam_stepfunctions Hey!!! How you doing? In this post, we’ll look at how to build a workflow, using SAM as IaC, Appsync, and python. Prerequisites Install AWS Cli (https://docs.aws.amazon.com/cli/latest/userguide/cli-c...

Welcome to the 4th and final post in this series.
PART 1
PART 2
PART 3
In the last 3 posts, we setup Amplify to Work with Flutter,
In this post, we'll look at how to create and display comments for a post in real time.
Comment entity is in this branch Comment Branch.
comments and any post they like.
post and comment entity share a one to many relationship.
createComment function
Future<bool> createComment(String userId,Post post) async{
loading = true;
try {
Comment comment = Comment(commentText: commentController.text.trim(),userId: userId,
postID:post.id,post: post,createdOn: TemporalDateTime.now(), updatedOn: TemporalDateTime.now());
await Amplify.DataStore.save(comment);
loading = false;
return true;
}catch(ex){
print(ex.toString());
loading = false;
return false;
}
}
When creating a comment, we need to understand that, firstly, a comment is made by a user. So we need the userId of that user to identify them as the creator of that comment.
Secondly, a comment is made on a post. Many comments can be made on a single post.
We need to identify the post, the comment was made on. So we add the post Object and postId to the comment object.
Finally, we call await Amplify.DataStore.save(comment) to save the comment object to the datastore.
queryAllCommentsForPost
We should be able to display all the comments made under a particular post, lastest first.
Future<List<Comment>>queryAllCommentsForPost(String postId) async{
List<Comment> comments= await Amplify.DataStore.query(Comment.classType,
where: Comment.POSTID.eq(postId),
sortBy: [Comment.CREATEDON.descending()]);
print("comments are "+comments.toString());
return comments;
}
commentStream = Amplify.DataStore.observe(Comment.classType).listen((event) {
if (commentsRepo.comments.isEmpty) {
commentsRepo.comments.add(event.item);
}else{
if (commentsRepo.comments[0].id != event.item.id) {
commentsRepo.comments.insert(0, event.item);
print('Received event of type ' + event.eventType.toString());
print('Received post ' + event.item.toString());
}
}
});
Subscriptions fire off multiple times. We don't want to save multiple copies of the same comment in our listview.
So firstly, if the list object is empty, we just add a comment item to it.
If it's not empty, then we check to see if there is already that same comment item. If there isn't, we add the comment to the first position in the list.