问题
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.
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();
});
回答1:
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
});
来源:https://stackoverflow.com/questions/62183435/dart-flutter-how-to-change-the-timer-inside-periodic-after-every-time