Enabling rewarded ads

Warning.

This is an archived version of the documentation. Actual documentation for all platforms can be found here.

A rewarded ad is a configurable full-screen ad. The user gets a reward for viewing the ad.

Creating and displaying RewardedAd

  1. Add the import:

    import 'package:yandex_mobileads/mobile_ads.dart';
    Copied to clipboard
  2. Create a RewardedAd class object. You can only use the asynchronous method to create the object:

    final ad = await RewardedAd.create(
     adUnitId: 'R-M-XXXXXX-Y',
     onAdLoaded: () { 
         /* Do something */
     },
     onAdFailedToLoad: (error) { 
         /* Do something */
     },
    );
    Copied to clipboard
  3. After you create the RewardedAd class object, load the ads. To load an ad, use the load method that accepts an optional AdRequest object.

    await ad.load(adRequest: AdRequest());
    Copied to clipboard

    You can wait for your ad to load asynchronously using the await keyword.

  4. Rewarded ads are loaded in the background immediately after the load method is called. To display an ad, call the show method:

    await ad.show();
    Copied to clipboard

    You can wait for the ad to start displaying asynchronously.

  5. Alternatively, you can use the waitForDismiss asynchronous method to wait until the end of the ad serving and/or reward:

    Reward? reward = await ad.waitForDismiss();
    Copied to clipboard

Example of working with rewarded ads

The code demonstrates how to create and configure a RewardedAd object, and how to load and display a rewarded ad:

Future<void> showRewardedAd() async {
  final ad = await RewardedAd.create(
    adUnitId: 'demo-rewarded-yandex',
    onAdLoaded: () { 
        /* Do something */
    },
    onAdFailedToLoad: (error) { 
        /* Do something */
    },
  );
  await ad.load(adRequest: AdRequest());
  await ad.show();
  final reward = await ad.waitForDismiss();
  if (reward != null) debugPrint('got ${reward.amount} of ${reward.type}');
}
Copied to clipboard

If an ad is integrated this way, the ad unit appears when showRewardedAd is called.

To see how the ad will be displayed in the app, use a demo AdUnitId:
  • demo-rewarded-yandex