I want to show the Admob App an open Ad and for that I followed this link and is working fine. Now Ad is showing whenever I opened the app but I want to show ad only when a variable is divisible by 3. For like ad comes to the user 3 times and the ad dispose of and for the six-time show ad again site i followed
CodePudding user response:
You can wrap these in an if statement when the variable is divisible by 3.
//Load AppOpen Ad
appOpenAdManager.loadAd();
//Show AppOpen Ad After 8 Seconds
Future.delayed(const Duration(seconds: 8)).then((value) {
//Here we will wait for 8 seconds to load our ad
//After 8 seconds it will go to HomePage
appOpenAdManager.showAdIfAvailable();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const HomePage(),
),
);
});
CodePudding user response:
Use any local storage libraries / shared preferences
create variable as storing open openedCount=0;
read it from storage/preference
Now wrap your like
if(openedCount % 3 == 0)
{
openedCount =0;
//store it again
appOpenAdManager.loadAd();
//Show AppOpen Ad After 8 Seconds
Future.delayed(const Duration(seconds: 8)).then((value) {
//Here we will wait for 8 seconds to load our ad
//After 8 seconds it will go to HomePage
appOpenAdManager.showAdIfAvailable();
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const HomePage(),
),
);
});
}
else{
// increment the value of openedCount in the storage
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const HomePage(),
),
);
}