I'm trying to link a countdown timer in Dart with my Firebase database, the countdown starts (timestamp) when the post is published and ends 10 seconds later.
My Dart code works, when I post to the database, my countdown is linked to the post, and the post is removed from the database onEnd, however, the timer is not linked to the post, and every refresh of the page restarts.
This code illustrates the working conditions described in the previous paragraph.
TweenAnimationBuilder<Duration>(
duration: Duration(seconds: 10),
tween: Tween(begin: Duration(seconds: 10), end: Duration.zero),
onEnd: () {
deletePost(
widget.snap['postId']
.toString(),
);
I want Begin to be the post (timestamp) in the Firebase database, so I tried something like this. 'datePublished' is the time the post was created in Firebase.
TweenAnimationBuilder<Duration>(
duration: Duration(seconds: 10),
tween: Tween(begin: widget.snap['datePublished'], end: Duration.zero),
onEnd: () {
deletePost(
widget.snap['postId']
.toString(),
);
and it returns
Expected a value of type 'Duration?', but got one of type 'Timestamp'
Firebase does not have a type 'Duration' from what I see so is there another way to do this?
Update
Per some suggestions and as a way to create a link to the back-end (Firebase) I created a Firestore method 'timer' with a integer value of secondsPerMinute and passed it like this:
TweenAnimationBuilder<Duration>(
duration: Duration(seconds: widget.snap['timer']),
tween: Tween(begin: Duration(seconds: 10), end: Duration.zero),
onEnd: () {
deletePost(
widget.snap['postId']
.toString(),
);
This creates a correct output in relation to the back-end however, the front-end and back-end are still not "attached" so to speak (every time the page is refreshed the countdown starts over from 10 seconds) my goal is to create a permanent relationship between the creation of the post and the post being deleted after 10 seconds no matter if the user navigates away from the page or closes the page/application all together.