repeat the interstatial ad after 30 sec in flutter code example

Example 1: showing ads every x seconds flutter

import 'dart:async'; // <-- put  it on very top of your file

Timer _timerForInter; // <- Put this line on top of _MyAppState class


void initState() {
  // Add these lines to launch timer on start of the app
  _timerForInter = Timer.periodic(Duration(seconds: 20), (result) {
  _interstitialAd = createInterstitialAd()..load();
  });
  super.initState();
 }

 
 void dispose() {
   // Add these to dispose to cancel timer when user leaves the app
   _timerForInter.cancel();
   _interstitialAd.dispose();
   super.dispose();
}

Example 2: how to show ad every second flutter

import 'dart:async'; // <-- put  it on very top of your file

Timer _timerForInter; // <- Put this line on top of _MyAppState class


void initState() {
  // Add these lines to launch timer on start of the app
  _timerForInter = Timer.periodic(Duration(seconds: 20), (result) {
  _interstitialAd = createInterstitialAd()..load();
  });
  super.initState();
 }

 
 void dispose() {
   // Add these to dispose to cancel timer when user leaves the app
   _timerForInter.cancel();
   _interstitialAd.dispose();
   super.dispose();
}

Tags:

Dart Example