如何在应用程序中指定间隔后显示卡
我想每周在我的应用程序中每周显示一张卡。
谁能帮我怎么做?
我在init状态中使用future.delayed
为其设置持续时间“ 7天”。
但是我认为这是错误的。
那我该怎么做呢?
void initState() {
Future.delayed(Duration(days: 7), () {
showBottomSheet(context);
});
super.initState();
}
I want to show the card on the main page once a week in my app.
Can anyone help me how can I do that?
I use Future.delayed
in the init state and set duration "7 days" for it.
But I think it is wrong.
So how can I do that?
void initState() {
Future.delayed(Duration(days: 7), () {
showBottomSheet(context);
});
super.initState();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以做一件事情
You can do one thing
尝试使用
timer.run.run
run 参考计时器
,Try to use
Timer.run
referTimer
,如果不持续数据,您就无法做到这一点。当用户关闭应用程序,将其移至其移动操作系统的背景或将其设备置于备用状态时,您纯粹在应用程序中所做的任何事情都将消失。
保存您希望它出现在某个地方的日期和时间。 sharedPreferences 将是一个选项,后端API或Firestore将是另一个。
当您的应用程序启动时,请从商店阅读该日期,并找出是否该显示横幅。另外,如果您怀疑您的应用程序已开放很长时间,并且希望它可以自发地出现,请设置a 计时器在您的应用程序运行时定期运行此检查。
显示横幅后,将下一个日期添加到您选择的数据存储中。
You cannot do that without persisting data. Anything you do purely in your app will be gone when the user closes your app, moves it to the background of their mobile operating system or puts their device into standby.
Save the date and time you want it to appear somewhere. SharedPreferences would be one option, a backend API or the FireStore would be another.
When your app starts, read that date from the store and find out if it's time to show your banner. Alternatively, if you suspect your app is open for a long time and you want it to appear spontanously, set a timer to run this check periodically while your app is running.
Once you have shown the banner, add the next date to show it to the data store you picked.