Skip to content

Instantly share code, notes, and snippets.

@Anirudhk07
Created July 11, 2020 06:47
Show Gist options
  • Save Anirudhk07/87c1484ae0d1f08b206b3848d6d55798 to your computer and use it in GitHub Desktop.
Save Anirudhk07/87c1484ae0d1f08b206b3848d6d55798 to your computer and use it in GitHub Desktop.
class _GameRouteState extends State<GameRoute> implements QuizEventListener {
...
// TODO: Add _isRewardedAdReady
bool _isRewardedAdReady;
...
// TODO: Implement _loadRewardedAd()
void _loadRewardedAd() {
RewardedVideoAd.instance.load(
targetingInfo: MobileAdTargetingInfo(),
adUnitId: AdManager.rewardedAdUnitId,
);
}
// TODO: Implement _onRewardedAdEvent()
void _onRewardedAdEvent(RewardedVideoAdEvent event,
{String rewardType, int rewardAmount}) {
switch (event) {
case RewardedVideoAdEvent.loaded:
setState(() {
_isRewardedAdReady = true;
});
break;
case RewardedVideoAdEvent.closed:
setState(() {
_isRewardedAdReady = false;
});
_loadRewardedAd();
break;
case RewardedVideoAdEvent.failedToLoad:
setState(() {
_isRewardedAdReady = false;
});
print('Failed to load a rewarded ad');
break;
case RewardedVideoAdEvent.rewarded:
QuizManager.instance.useHint();
break;
default:
// do nothing
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment