Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the rewarded video listener in flutter?

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 ?

like image 907
ViralCode Avatar asked Sep 11 '25 09:09

ViralCode


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(...)
like image 127
CopsOnRoad Avatar answered Sep 12 '25 22:09

CopsOnRoad