如何显示所有用户的倒数时间

编程入门 行业动态 更新时间:2024-10-27 00:35:45
本文介绍了如何显示所有用户的倒数时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在构建一个颤动的拍卖应用程序,我被困在拍卖产品的倒计时时间,所以我使用Firebase实时数据库.我必须确保所有用户都同时看到倒数计时.无论是搜索关键字,类似示例还是对我有帮助的内容,请帮助我.而且我可以使用nodejs进行协助,

I am building a flutter auction application, I am stuck at the countdown time of an auction product so I use firebase realtime database. I have to make sure all users see the countdown at the same time. Please help me whether it's just a keyword to search for, a similar example or something that can help me. And I can use nodejs to assist,

这是我的数据库,我想要当用户发布他们的产品时,倒数计时,然后获取该数据以在屏幕上显示它.我在哪里放置倒数计时器?在扑火或火力中.我在哭谢谢你所做的一切,

This is my database, I want when a user posts a product of theirs, the time countdown, and I get that data to display it on the screen. Where do I put that countdown timer? In flutter or firebase. I'm crying. Thank you for everything,

推荐答案

一个简单的解决方案是设置拍卖的结束时间 DateTime .例如,如果您希望两个小时后终止拍卖,则可以添加

One simple solution is to set the ending DateTime of your auction. For example, if you want your auction to be terminated after two hours, you can add

endingTime = DateTime.now().add(Duration(hours: 2))

到Firebase实时数据库,然后当用户参加拍卖时,您可以使用 Timer.periodic 计算每1秒钟的剩余时间,并在当前 DateTime 超出了终止时间:

to Firebase realtime database, and then when users come to your auction, you can just use a Timer.periodic to calculate the remaining time for every 1 second, and stop the timer when the current DateTime exceeds the termination time:

Timer.periodic(Duration(seconds: 1), (timer) { remainingTime = endingTime.difference(DateTime.now()); if (remainingTime <= Duration.zero) { timer.cancel() } });

最后,您可以只使用 setState 渲染 remainingTime ,或使用 StreamBuilder 实现 StreamController 它.希望对您有所帮助.

And finally, you can just use setState to render remainingTime, or implement StreamController with StreamBuilder to render it. Hope it helps.

更多推荐

如何显示所有用户的倒数时间

本文发布于:2023-10-21 17:37:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1514905.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:倒数   时间   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!