飞镖/颤振每次之后如何定期更改计时器 [英] Dart/flutter how to change the timer inside periodic after every time

查看:74
本文介绍了飞镖/颤振每次之后如何定期更改计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为在我的应用中展示广告制定自定义逻辑,因此,当用户在弹出1分钟后弹出广告时打开应用,然后假设这1分钟每次都会增加1分钟,因此x为2 3然后4 ...等等。

I'm making a custom logic for showing ads in my app, so when the user opens the app after 1 min pops up an ad then supposed this 1 min to get increased by 1 min every time, So x be 2 then 3 then 4 ...etc.

我尝试这样做,但对我没有用(每隔1分钟显示一次广告就不会增加);

I tried to do so, but didn't work for me ( showing the ad every 1 min not increase it );

int x = 1;
Timer.periodic(Duration(minutes: x), (timer) { 
  x = x + 1;
  interstitialAd.load();
});


推荐答案

我认为您无法做到。您也可以根据情况取消当前计时器并启动新计时器。检查以下伪代码

I think you cannot do it. You can alternatively cancel the current timer and start a new timer based on conditions. Check the following pseudo-code

  Timer.periodic(Duration(minutes: 5), (timer) {
      if(condition){
        timer.cancel();
        createNewPeriodicTask();
      }
      // task code
  });

这篇关于飞镖/颤振每次之后如何定期更改计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆