How to controll time indepedently. In this post, we will see how to resolve How to controll time indepedently from time on users phone in my firebase app?
Question:
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 youBest Answer:
the solution is to not get the date from the local device, but get it from the firebasetimestamp
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:[code]Timestamp(Timestamp.now().millisecondsSinceEpoch , 24*60*60*1000)
[/code]
Timestamp
we set in the database with:[code]FieldValue.serverTimestamp()
[/code]
Timestamp
with this:[code] final firestoreTimestamp = /* the Timestamp object */;
firestoreTimestamp.toDate();
[/code]
If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com