Rewarded ads are ads that users have the option of interacting with in exchange for in-app rewards. This guide shows how to integrate rewarded ads from AdMob 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 rewarded ads:

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

A RewardedAd requires an adUnitId, an AdRequest, and an AdListener with the onRewardedAdUserEarnedReward callback implemented. The following example instantiates a rewarded ad:

final RewardedAd myRewarded = RewardedAd(
  adUnitId: '<ad unit ID>',
  request: AdRequest(),
  listener: AdListener(
    onRewardedAdUserEarnedReward: (RewardedAd ad, RewardItem reward) {

Rewarded 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:

  // 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.'),
  // Called when a RewardedAd triggers a reward.
  onRewardedAdUserEarnedReward: (RewardedAd ad, RewardItem reward) {
    print('Reward earned: $reward');

Load ad

After a RewardedAd is instantiated, load() must be called before it can be shown on the screen.


Display ad

A RewardedAd 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 add by calling show() after the ad is loaded.;

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 practice for when to call dispose() is in the AdListener.onAdFailedToLoad or AdListener.onAdClosed callbacks.

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