Implementation
static Future<bool> showReward() async {
if (kIsWeb) {
AdsenseAdsView.showInter();
}
/// use this to check if user was rewarded
bool anser = false;
await RewardedAd.load(
adUnitId: "ca-app-pub-8286573828419993/5994759567",
request: const AdRequest(),
rewardedAdLoadCallback: RewardedAdLoadCallback(
onAdLoaded: (RewardedAd rewAd) {
log('$rewAd loaded.');
// Keep a reference to the ad so you can show it later.
rewAd.fullScreenContentCallback = FullScreenContentCallback(
onAdShowedFullScreenContent: (RewardedAd ad) =>
log('$ad onAdShowedFullScreenContent.'),
onAdDismissedFullScreenContent: (RewardedAd ad) {
log('$ad onAdDismissedFullScreenContent.');
ad.dispose();
},
onAdFailedToShowFullScreenContent: (RewardedAd ad, AdError error) {
log('$ad onAdFailedToShowFullScreenContent: $error');
ad.dispose();
},
onAdImpression: (RewardedAd ad) => log('$ad impression occurred.'),
);
rewAd.show(
onUserEarnedReward: (
AdWithoutView ad,
RewardItem rewardItem,
) {
// Reward the user for watching an ad.
FirebaseAnalytics.instance.logEarnVirtualCurrency(
virtualCurrencyName: rewardItem.type,
value: rewardItem.amount,
);
anser = true;
},
);
},
onAdFailedToLoad: (LoadAdError error) {
log('RewardedAd failed to load: $error');
},
),
);
return anser;
}