简体   繁体   中英

How to limit the user to play quiz from firestore only once per day?

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.

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.

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:

yes shared preference will help you here is the example .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM