2

I have a post list which there is a Post Likes where user can likes the post double clicking on the picture:

GestureDetector( onDoubleTap: (){ FirebaseFirestore.instance.collection('SocialPost').doc(post[index]['postID']).update({ 'likes': FieldValue.increment(1), }); }, 

but of course if the user clicks many times on the picture the number will increase according to the times he clicks.. I want that the user just when he click the number increase by 1 and stop if he clicks again no more action. how to handle this situation?

1 Answer 1

2

There are a few different ways to have this you could have a users collection for each user and in the documents you could store the posts the user liked or

In your SocialPost's collection you could store the ids of users that liked this post and there before you increment the value, you can check if the user already liked this post (So the user ids array contains the current user's id)

Only if the array does not contain this id you would allow it, and then after incrementing you would add the user's id to the array.

Sign up to request clarification or add additional context in comments.

4 Comments

I think the second Option is the second One
Yeah i agree the first option would cost more but if you want to display all the posts a user liked, you could also implement liked documents in the user collection
One more question... How to create a List of an Array for example this list have to ADD each user into this array: 'userLikedList: [ HERE THE VALUE WHICH ADD EACH USER TO THE LIST ]
firebase.google.com/docs/reference/js/… You can use array union fieldValue to add a new id to the array

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.