Below we show a simple example to understand how rewarded ads work:
import'package:wortise/rewarded_ad.dart';RewardedAd _rewardedAd;// Create an interstitial_rewardedAd =RewardedAd('Wortise Ad Unit ID', (event, args) {// This listener will be invoked when an event happens});// Request an adawait _rewardedAd.loadAd();/* ... */// Show the ad if availableif (await _rewardedAd.isAvailable) {await _rewardedAd.showAd();}
The RewardedAd class constructor admits a third parameter, called reloadOnDismissed, that when it is set to true (the default value is false) allows the rewarded to automatically load a new ad when the current one is dismissed.
Listener events
The assigned listener to an RewardedAd can receive the following events:
// The ad has been clickedRewardedAdEvent.CLICKED// The ad has been completed// (the 'amount', 'label' y 'success' arguments are passed)RewardedAdEvent.COMPLETED// The ad has been dismissedRewardedAdEvent.DISMISSED// The ad could not be loadedRewardedAdEvent.FAILED_TO_LOAD// The ad could not be shownRewardedAdEvent.FAILED_TO_SHOW// The ad has generated an impressionRewardedAdEvent.IMPRESSION// The ad has been loadedRewardedAdEvent.LOADED// The ad has been shownRewardedAdEvent.SHOWN
Below, we show a small example about how to obtain the reward once the ad has completed successfully: