I'm trying to implement Ads in my App. Currently I am working on Google Ad Mobs Rewarded Video Ads. My Problem is, that after the first time I press the button which should load the ad an error becomes:
Unhandled Exception: PlatformException(ad_not_loaded, show failed for rewarded video, no ad was loaded, null)
is thrown, but if I press again it works properly. I have attached some relevant Code
Setting the targeting Info, loading the ad and creating a listener:
@override
void initState() {
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
);
RewardedVideoAd.instance.load(
targetingInfo: targetingInfo,
adUnitId: RewardedVideoAd.testAdUnitId);
RewardedVideoAd.instance.listener =
(RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
if (event == RewardedVideoAdEvent.rewarded) {
Navigator.push(
context,
this.route);
}
else if(event == RewardedVideoAdEvent.failedToLoad){
Navigator.push(
context,
this.route);
}
};
super.initState();
}
The Button which starts the ad (it is located in the build method of the same class):
GestureDetector(
child: AdButton(theme.wopGH, "Gratis spielen"),
onTap: () {
RewardedVideoAd.instance.show();
},
),