i try to reload Rewarded Video Ads, when i call RewardedVideoAd.instance.load(adUnitId: \"xxx\", targetingInfo: xyz);
i find below error :
Seems like the issue was with the event completed
. Check out this code.
MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: ['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: [], // Android emulators are considered test devices
);
bool _loaded = false;
@override
void initState() {
super.initState();
// load ad in the beginning
RewardedVideoAd.instance
.load(adUnitId: RewardedVideoAd.testAdUnitId, targetingInfo: targetingInfo)
.catchError((e) => print("error in loading 1st time"))
.then((v) => setState(() => _loaded = v));
// ad listener
RewardedVideoAd.instance.listener = (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
if (event == RewardedVideoAdEvent.closed) {
RewardedVideoAd.instance
.load(adUnitId: RewardedVideoAd.testAdUnitId, targetingInfo: targetingInfo)
.catchError((e) => print("error in loading again"))
.then((v) => setState(() => _loaded = v));
}
};
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(
"Loaded = ${_loaded}",
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
),
),
floatingActionButton: FloatingActionButton(
// show ad on FAB click
onPressed: () async {
await RewardedVideoAd.instance.show().catchError((e) => print("error in showing ad: ${e.toString()}"));
setState(() => _loaded = false);
},
),
);
}