-
-
Notifications
You must be signed in to change notification settings - Fork 153
Interstitial Ads
Elias edited this page Oct 27, 2020
·
2 revisions
Make sure you have initialize the plugin first. You can learn how to do this in the Installation Wiki Page
Showing Interstitial Ads
// First, create an interstitial ad
AdmobInterstitial interstitialAd = AdmobInterstitial(
adUnitId: AdmobInterstitial.testAdUnitId,
);
// Interstitials must be loaded before shown.
// Make sure to always load them ahead so they can be
// available to be shown immediately to the user
interstitialAd.load();
// Check if the ad is loaded and then show it
if (await interstitialAd.isLoaded) {
interstitialAd.show();
}
// Finally, make sure you dispose the ad if you're done with it
interstitialAd.dispose();
Same as banner ads, you can attach a listener to interstitials too. For example if you wish to:
- Show the interstitial as soon as it is loaded
- Load a new ad and show it as soon as the old one is closed
- Get your users stuck in an interstitial ads loop to maximize revenue
- Get your Admob account banned and lose all your earnings
You can do something like this (Don't do it!):
AdmobInterstitial interstitialAd;
interstitialAd = AdmobInterstitial(
adUnitId: AdmobInterstitial.testAdUnitId,
listener: (AdmobAdEvent event, Map<String, dynamic> args) {
if (event == AdmobAdEvent.loaded) interstitialAd.show();
if (event == AdmobAdEvent.closed) interstitialAd.load();
if (event == AdmobAdEvent.failedToLoad) {
// Start hoping they didn't just ban your account :)
print("Error code: ${args['errorCode']}");
}
},
);