I am developing a Flutter quiz app for learning purposes using Cloud Firestore. The app is working fine, but the problem is that same user can read and play quiz multiple number of times in a single day. I want to restrict users to play quizzes only once per day. My research is not helping me out, so I decided to seek help here. How can I impose restrictions on the number of times the quiz played by users per day? Any help will be appreciated a lot.

- 130,605
- 17
- 163
- 193

- 755
- 1
- 6
- 14
-
Please share your code about how you fetch the quiz data. Are you fetching data directly from Firestore or do you use Cloud functions? – Dharmaraj May 21 '21 at 05:51
3 Answers
if I interpreted your problem correctly then this will work for you...
- when a user enters the game you should set the variable in shared preference like {'isJoined' : 'true' , 'joinedTime': 'dd-mm-yyyy'}
- now in this case you can have multiple logic I will suggest you if your time is fixed then you can compare the current time with last joined time.

- 160
- 1
- 7
-
Yes you can save data into shared pref or in cloud firestore too...So you will check if playedDate not eqauls today's date , then user can play else cannot....But this have some flaws as users can easily change date of their devices – Daniyal Dolare May 21 '21 at 06:38
-
@DaniyalDolare device date doesn't matter...when the user clicked again he just have to get the current time like this: DateTime dt = DateTime.now(); – Why_So_Ezz May 21 '21 at 06:41
-
may i have some more explanation, i think your idea is going to help me . – prabin maharjan May 21 '21 at 08:20
I want to restrict users to play the quiz only once per day.
The simplest solution I can think of is to create a new field in each User object called "readyToPlay". This field should have the initial value of "true". As soon as the user finishes the first game, change the value of the field to "false". Then simply restrict the possibility to play the game according to this field. So you have to check at the beginning of each game, against this newly added field.
To reset the value of this field to "true", every single day, I recommend you write a function in Cloud Functions for Firebase and call it once a day using Cloud Scheduler, as explained in my answer from the following post:

- 130,605
- 17
- 163
- 193
-
-
You need to follow the documentation, as mentioned in my answer. However, if you have a hard time implementing it, show us what you have tried by posting a new question using its own [MCVE](https://stackoverflow.com/help/mcve), so I and other Firebase developers can help you. – Alex Mamo May 21 '21 at 08:24