4

I can't figure out how to use the listener to reward the user for watching the video.

package page : https://pub.dartlang.org/packages/firebase_admob

RewardedVideoAd.instance.listener =
    (RewardedVideoAdEvent event, [String rewardType, int rewardAmount]) {
  if (event == RewardedVideoAdEvent.rewarded) {
    setState(() {
      // Here, apps should update state to reflect the reward.
      _goldCoins += rewardAmount;
    });
  }
};

All I managed to do is display the ad, I have no clue how to use the listener.

This is an example: https://github.com/Maherr/listener/blob/master/lib/main.dart

How to change rewarded to true ?

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
ViralCode
  • 189
  • 1
  • 2
  • 8

1 Answers1

4

First, you are using the outdated code. This one is the latest one. Notice that it has optional named parameters {} instead of optional positional parameters [].

RewardedVideoAd.instance.listener =
    (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
  if (event == RewardedVideoAdEvent.rewarded) {
    setState(() {
      rewarded = true; 
    });
  }
};

This is how listener works. You don't have to assign this listener to anywhere. All you need to do is call

RewardedVideoAd.instance.load(...)
CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
  • Hi @CopsOnRoad, where i can place `RewardedVideoAd.instance.listner` ? can it place at init() ? – questionasker Jul 26 '19 at 01:09
  • @anunixercoder Yes, you can put it in `initState()`. – CopsOnRoad Jul 26 '19 at 02:07
  • Hi @CopsOnRoad, i have put it at `initState()` but cant get ads reloaded. i have ask a question here https://stackoverflow.com/questions/57212679/flutter-rewarded-video-ads-error-when-reload-ad-not-loaded-show-failed-for thank you – questionasker Jul 26 '19 at 03:17