Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to controll time indepedently from time on users phone in my firebase app?

I have a Flutter app where users can predict the outcome of a soccer match. The problem is that if the user changes the time on their phone they can still predict even after it has ended. How do I prevent this so that it’s independent of the time on each user’s phone?
Thank you

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

the solution is to not get the date from the local device, but get it from the firebase timestamp that it offers, as example if we say that you want to do it from now until tomorrow at the same time, you can save it to your DB, using:

Timestamp(Timestamp.now().millisecondsSinceEpoch , 24*60*60*1000)

in your case, you need to compare the Timestamp we set in the database with:

FieldValue.serverTimestamp()

also, you can get a DateTime from a Timestamp with this:

 final firestoreTimestamp = /* the Timestamp object */;
 firestoreTimestamp.toDate();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading