Enabling interstitial ads
This is an archived version of the documentation. Actual documentation for all platforms can be found here.
An interstitial ad is a configurable full-screen ad that reacts to clicks.
Creating and displaying InterstitialAd
Add the import:
import 'package:yandex_mobileads/mobile_ads.dart';
Copied to clipboardCreate an object of the
InterstitialAd
class. You can only use the asynchronous method to create the object:final ad = await InterstitialAd.create( adUnitId: 'R-M-XXXXXX-Y', onAdLoaded: () { /* Do something */ }, onAdFailedToLoad: (error) { /* Do something */ }, );
Copied to clipboardAfter you create and configure the
InterstitialAd
class object, load the ads. To load an ad, use theload
method that accepts an optionalAdRequest
object.await ad.load(adRequest: AdRequest());
Copied to clipboardYou can wait for your ad to load asynchronously using the
await
keyword. If there's an error, theonAdFailedToLoad
method is called to terminate waiting.Interstitial ads are loaded in the background immediately after the
load
method is called. To display an interstitial ad, call theshow
method:await ad.show();
Copied to clipboardYou can wait for the ad to start displaying asynchronously.
Alternatively, you can use the
waitForDismiss
asynchronous method to wait until the end of ad serving:await ad.waitForDismiss();
Copied to clipboard
Example of working with interstitial ads
The code demonstrates how to create and configure an InterstitialAd
object, and how to load and display an interstitial ad:
Future<void> showInterstitialAd() async { final ad = await InterstitialAd.create( adUnitId: 'demo-interstitial-yandex', onAdLoaded: () { /* Do something */ }, onAdFailedToLoad: (error) { /* Do something */ }, ); await ad.load(adRequest: AdRequest()); await ad.show(); await ad.waitForDismiss(); }
Copied to clipboard
If an ad is integrated this way, the ad unit appears when showInterstitialAd
is called.
- demo-interstitial-yandex