Reputation: 4519
I want to show a countdown for an activity and it should show same value on each device. For this purpose I am trying to do the following:
ServerValue.timestamp
.ServerValue.timestamp
and end time from firebase field.Firstly I wanted to know if my logic is correct. Secondly, how do I add a duration to the server timestamp, for e.g. 60 seconds. In normal dateTime I think you can add duration using .add but couldn't find a method to do for server time. Thank you
I am using firebase_database
package to connect to firebase.
Upvotes: 2
Views: 1635
Reputation: 599176
Yup, that looks like a good approach to me. I recommend reading the process I outlined here: How to implement a distributed countdown timer in Firebase, which is similar to yours.
As you can see there, I don't perform an addition to ServerValue.timestamp
, but instead store the interval for the time as a separate value. This is much simpler than trying to add a value to the existing field, which would require an extra read and write and would make the code much more complex.
Upvotes: 2