Interstitial

Interstitial ads are full-screen ads that cover the interface of their host app. They're typically displayed at natural transition points in the flow of an app, such as between activities or during the pause between levels in a game. When an app shows an interstitial ad, the user has the choice to either tap on the ad and continue to its destination or close it and return to the app.

This guide explains how to integrate interstitial ads into a Flutter app.

Always test with test ads

When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account.

The easiest way to load test ads is to use our dedicated test ad unit ID for interstitials:

The test ad units are configured to return test ads for every request, and you're free to use them in your own apps while coding, testing, and debugging. Just make sure you replace them with your own ad unit IDs before publishing your app.

Instantiate ad

An InterstitialAd requires an adUnitId, an AdRequest, and an AdListener. The following example instantiates an interstitial ad:

final InterstitialAd myInterstitial = BanInterstitialAdnerAd(
  adUnitId: '<ad unit ID>',
  request: AdRequest(),
  listener: AdListener(),
);

Interstitial ad events

Through the use of AdListener, you can listen for lifecycle events, such as when an ad is closed or the user leaves the app. This example implements each method and logs a message to the console:

final AdListener listener = AdListener(
  // Called when an ad is successfully received.
  onAdLoaded: (Ad ad) => print('Ad loaded.'),
  // Called when an ad request failed.
  onAdFailedToLoad: (Ad ad, LoadAdError error) {
    print('Ad failed to load: $error');
  },
  // Called when an ad opens an overlay that covers the screen.
  onAdOpened: (Ad ad) => print('Ad opened.'),
  // Called when an ad removes an overlay that covers the screen.
  onAdClosed: (Ad ad) => print('Ad closed.'),
  // Called when an ad is in the process of leaving the application.
  onApplicationExit: (Ad ad) => print('Left application.'),
);

Load ad

After an InterstitialAd is instantiated, load() must be called before it can be shown on the screen:

myInterstitial.load();

Display ad

An InterstitialAd is displayed as an Overlay on top of all app content and is statically placed; thus, it can't be added to the Flutter widget tree. You can choose when to show the ad by calling show() after the ad is loaded.

myInterstitial.show();

This method can only be called after load() and after the AdListener.onAdLoaded method had been triggered. Once show() is called, an Ad displayed this way can't be removed programmatically and requires user input.

Once an ad has called load(), it must call dispose() when access to it is no longer needed. The best place for calling dispose() is in the AdListener.onAdFailedToLoad or AdListener.onAdClosed callbacks.

That's it! Your app is now ready to display interstitial ads.

Next steps