How to use the rewarded video listener in flutter?

Viewed 1752

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 ?

1 Answers

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(...)
Related