Closed erperejildo closed 2 years ago
I have different pages where I need to display a reward ad. The events work fine on all of them but since I open a new ad, a new listener is created.
Provider.of<AdState>(context, listen: false).showRewardedAd(); Provider.of<AdState>(context, listen: false) .rewardedAd .onEvent .listen((Map<RewardedAdEvent, dynamic> e) { final event = e.keys.first; switch (event) { case RewardedAdEvent.earnedReward: print('*** Rewarded Ad successful.'); break; } }); ... Future<void> showRewardedAd() async { rewardedAd.onEvent.listen((event) {}).cancel(); // doesn't work if (!rewardedAd.isAvailable) { await rewardedAd.load(); } await rewardedAd.show(); rewardedAd.load(); }
How could I remove all the previous ones?
Fixed like this:
if (!rewardedAd.isAvailable) { await rewardedAd.load(); } await rewardedAd.show(); // cancel previous listeners rewardedAd = await RewardedAd() ..load();
I have different pages where I need to display a reward ad. The events work fine on all of them but since I open a new ad, a new listener is created.
How could I remove all the previous ones?