Rewarded video integration for Flutter
- Make sure that you have correctly integrated the Flutter Plugin into your app. Integration is outlined here.
- Make sure to initialize the SDK using LevelPlay Initialization API.
- You can find the AdUnitID in LevelPlay dashboard. Learn more here.
- This documentation is relevant for SDK 8.6.0+. Documentation for legacy APIs (SDK 8.6.0 and below) can be found here: manual rewarded video and automatic rewarded video.
Create Rewarded and Register to Events
Once you receive the onInitSuccess callback, you can create an ad unit using the relevant Ad Unit ID, as defined in the LevelPlay platform (Initializing the ironSource SDK step).
Set the rewarded listener for the rewarded ad unit created, to get informed of ad delivery.
final LevelPlayRewardedAd _rewardedAd = LevelPlayRewardedAd(adUnitId: [YOUR_AD_UNIT_ID]);
@override
void initState() {
super.initState();
_rewardedAd.setListener(this);
}
// LevelPlayRewardedAdListener methods
@override
void onAdLoaded(LevelPlayAdInfo adInfo) {}
@override
void onAdLoadFailed(LevelPlayAdError error) {}
@override
void onAdDisplayed(LevelPlayAdInfo adInfo) {}
@override
void onAdDisplayFailed(LevelPlayAdError error,
LevelPlayAdInfo adInfo) {}
@override
void onAdClosed(LevelPlayAdInfo adInfo) {}
@override
void onAdClicked(LevelPlayAdInfo adInfo) {}
@override
void onAdInfoChanged(LevelPlayAdInfo adInfo) {}
@override
void onAdRewarded(LevelPlayReward reward, LevelPlayAdInfo adInfo) {}
LevelPlay Rewarded Ad Callbacks
onAdLoaded – Provided when the ad is successfully loaded
onAdLoadFailed – Provided when the ad fails to load. Ad Unit information is included
onAdDisplayed – Provided when the ad is displayed. This is equivalent to an impression
onAdDisplayFailed (optional) – Provided when the ad fails to be displayed
onAdRewarded – Provided when the ad is rewarded. Ad Unit info and the reward info are included.
onAdClicked (optional) – Provided when the user clicks on the ad
onAdClosed – Provided when the ad is closed
onAdInfoChanged (optional) – Provided when the ad info is updated. Available when another ad has loaded, and includes a higher CPM/Rate
Load Rewarded Ad
Once you receive the onInitSuccess callback, you are ready to load a rewarded ad. This should be done using the method:
_rewardedAd.loadAd();
Show Rewarded Ad
You can show a rewarded ad after you receive onAdLoaded callback, using the showAd APIs.
If you are using placements, share their name as part of the API, as shown below.
// Show ad without placement
_rewardedAd.showAd();
// Show ad with placement
_rewardedAd.showAd(placement: [YOUR_PLACEMENT]);
Check ad ready
To avoid show failures, and to make sure the ad could be displayed correctly, we recommend using the following API, before calling the showAd() API.
isAdReady – returns true if ad was loaded successfully and ad unit is not capped, or false otherwise.
isPlacementCapped – returns true when a valid placement is capped. If the placement is not valid, or not capped, this API will return false.
// Check that ad is ready and that the placement is not capped
if(_rewardedAd.isAdReady() && !LevelPlayRewardedAd.isPlacementCapped([YOUR_PLACEMENT])) {
_rewardedAd.showAd(placement:[YOUR_PLACEMENT]);
}
Once the ad was displayed successfully to the player, you can load another ad, repeating the Load Rewarded Ad step. There is no need to create a new ad entity, when loading a single ad at a time.
Reward the User
The LevelPlay SDK will fire the onAdRewarded each time the user successfully completes a video.
The onAdRewarded and onAdClosed are asynchronous. Make sure to set up your listener to grant rewards even in cases where onAdRewarded is fired after the onAdClosed.
@override
void onAdRewarded(LevelPlayReward reward, LevelPlayAdInfo adInfo) {
// Implement logic to grant the reward to the user
}
Multiple Ad Unit Rewarded APIs
Legacy | Ad Unit (new) | |
Class | IronSource | LevelPlayRewardedAd |
API | loadRewardedVideo | loadAd |
showRewardedVideo | showAd | |
isRewardedVideoPlacementCapped | isPlacementCapped | |
isRewardedVideoAvailable | isAdReady | |
placement.getRewardName | reward.name | |
placement.getRewardAmount | reward.amount |
Full Implementation Example of Rewarded Ad
final LevelPlayRewardedAd _rewardedAd = LevelPlayRewardedAd(adUnitId: 'YOUR_AD_UNIT_ID');
@override
void initState() {
super.initState();
_rewardedAd.setListener(this);
_rewardedAd.loadAd();
}
@override
void onAdRewarded(LevelPlayReward reward, LevelPlayAdInfo adInfo) {
// Implement your logic here...
}
@override
void onAdClicked(LevelPlayAdInfo adInfo) {
// Implement your logic here...
}
@override
void onAdClosed(LevelPlayAdInfo adInfo) {
// Implement your logic here...
}
@override
void onAdDisplayFailed(LevelPlayAdError error, LevelPlayAdInfo adInfo) {
// Implement your logic here...
}
@override
void onAdDisplayed(LevelPlayAdInfo adInfo) {
// Implement your logic here...
}
@override
void onAdInfoChanged(LevelPlayAdInfo adInfo) {
// Implement your logic here...
}
@override
void onAdLoadFailed(LevelPlayAdError error) {
// Implement your logic here...
}
@override
void onAdLoaded(LevelPlayAdInfo adInfo) {
// Implement your logic here, for example showing the ad
_rewardedAd.showAd();
}
// Rest of the widget
// End of widget...
Done!
You are now all set to deliver Rewarded Video in your application.