Flutter firebase-admob check if rewarded video is loading

1,394

You need to use the await keyword

 void showRewardedAd() async {
    try {
      await RewardedVideoAd.instance.load(
          adUnitId: RewardedVideoAd.testAdUnitId, targetingInfo: targetingInfo);

      await RewardedVideoAd.instance.show();
    } on PlatformException catch (e) {
      print(e.message);
    }
  }

and on your listener method add below lines

 if (event == RewardedVideoAdEvent.loaded) {
        setState(() {
         isRewardADLoaded = true;
        });
      }
Share:
1,394
John
Author by

John

Updated on December 09, 2022

Comments

  • John
    John over 1 year

    Using flutter and this plugin (https://pub.dartlang.org/packages/firebase_admob),

    How can I check if the Rewarded video is load?

    I received this Exception :

    PlatformException(ad_not_loaded, show failed for rewarded video, no ad was loaded, null)
    

    but i can't capture it.

    Thank you.

  • Wenhui  Luo
    Wenhui Luo about 4 years
    is it necessary to wrap isRewardADLoaded = true; inside setState?
  • Wenhui  Luo
    Wenhui Luo about 4 years
    is it better to move RewardedVideoAd.instance.load() into initState? and only try show()