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();
});


Solution 1: Sanjay Sharma

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
  });