Home > Software design >  should i use firestore database to store a boolean value for my button state (pressed/unpressed)
should i use firestore database to store a boolean value for my button state (pressed/unpressed)

Time:02-21

I'm building a food delivery app using Firestore to populate a RecyclerView, I have a button in every view in RecyclerView. I just want to know if I use Firestore boolean to save my buttons state in view, and give permission to the user to change the boolean value when the button is pressed. it will be a good idea to save the state of RecyclerView's view. The problem is if a user changes the boolean value in Firestore, all the users will get the same value and all the users will get some state of the button. is there any way to overcome this problem, please help?

CodePudding user response:

According to your comment:

All the products have their separate boolean in Firestore, this is my Product model class (String name, String price, boolean for button)

It's not a solution since that boolean value is the same for all users. What you have to do is to add an array type field inside each product document. When a user clicks the button add his UID inside the array. In this way, you'll always know which user clicked the button.

After doing this change, when displaying products, simply if the UID exists in the array. If it exists enable the button otherwise disable it.

  • Related