如何在应用程序中指定间隔后显示卡

发布于 2025-02-05 18:39:42 字数 286 浏览 2 评论 0原文

我想每周在我的应用程序中每周显示一张卡。

谁能帮我怎么做?

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冬天旳寂寞 2025-02-12 18:39:43

你可以做一件事情

获得工作日并为此设定条件

DateTime date = DateTime.now();
print("weekday is ${date.weekday}");
if date.weekday == MONDAY {
      do task for Monday
}else {do task for other day.. }

这将在周日的弗里达(Frieday)或电影报价(Frieday)上的特定日子(例如销售)非常简单易于触发事件。

You can do one thing

get weekday and set a condition on that like

DateTime date = DateTime.now();
print("weekday is ${date.weekday}");
if date.weekday == MONDAY {
      do task for Monday
}else {do task for other day.. }

this will very simple and easy away to trigger event on a specific day like sale on frieday or movie offer on Sunday..

甜味超标? 2025-02-12 18:39:43

尝试使用 timer.run.run run 参考 计时器

@override
  void initState() {
    super.initState();
    Timer.run(() {
      Future.delayed(Duration(days: 7), () {
         showBottomSheet(context);//This function display after every 7 Days
      });
    });    
   }

Try to use Timer.run refer Timer,

@override
  void initState() {
    super.initState();
    Timer.run(() {
      Future.delayed(Duration(days: 7), () {
         showBottomSheet(context);//This function display after every 7 Days
      });
    });    
   }
谁的年少不轻狂 2025-02-12 18:39:43

我想在我的应用中每周一次在主页上显示该卡。谁能帮我怎么做?

如果不持续数据,您就无法做到这一点。当用户关闭应用程序,将其移至其移动操作系统的背景或将其设备置于备用状态时,您纯粹在应用程序中所做的任何事情都将消失。

保存您希望它出现在某个地方的日期和时间。 sharedPreferences 将是一个选项,后端API或Firestore将是另一个。

当您的应用程序启动时,请从商店阅读该日期,并找出是否该显示横幅。另外,如果您怀疑您的应用程序已开放很长时间,并且希望它可以自发地出现,请设置a 计时器在您的应用程序运行时定期运行此检查。

显示横幅后,将下一个日期添加到您选择的数据存储中。

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?

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文