flutter - Google AdMob 奖励视频有时只加载

我正在尝试在我的应用程序中实现广告。目前我正在研究 Google Ad Mobs 奖励视频广告。我的问题是,在我第一次按下应该加载广告的按钮后,错误变为:

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

被抛出,但如果我再次按下它会正常工作。我附上了一些相关代码

设置定位信息,加载广告并创建监听器:

  @override
  void initState() {

    MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
        keywords: <String>['flutterio', 'beautiful apps'],
        contentUrl: 'https://flutter.io',
        childDirected: false,
    );

    RewardedVideoAd.instance.load(
        targetingInfo: targetingInfo,
        adUnitId: RewardedVideoAd.testAdUnitId);

    RewardedVideoAd.instance.listener =
        (RewardedVideoAdEvent event, {String rewardType, int rewardAmount}) {
      if (event == RewardedVideoAdEvent.rewarded) {
        Navigator.push(
                      context,
                      this.route);
      }
      else if(event == RewardedVideoAdEvent.failedToLoad){
        Navigator.push(
                      context,
                      this.route);
      }
    };
    super.initState();
  }

启动广告的按钮(位于同一类的构建方法中):

              GestureDetector(
                child: AdButton(theme.wopGH, "Gratis spielen"),
                onTap: () {
                  RewardedVideoAd.instance.show();
                },
              ),

最佳答案

只有在加载广告时才应启用您的按钮。在显示它之前,您必须等待它加载,这需要几秒钟。 在 initState 上,你应该为你的按钮分配一个状态,这样它就会被禁用。 加载广告后,您应该设置状态以启用它。

if (event == RewardedVideoAdEvent.loaded) {
    ...
}

https://stackoverflow.com/questions/58236352/

相关文章:

r - 在 R 中使用 RCurl 下载 NASA 卫星数据

reactjs - React Native - SetTimeout() 不工作。 t.apply

google-maps - google_maps_flutter 或任何其他用于 flutter

aws-lambda - 如何使用 CloudFormation 添加订阅过滤器?

swift - animateTransition 不再适用于 iOS 13 中以模态呈现的 vie

angular - Ionic Barcode Scanner 插件关闭按钮

python - TensorFlow 的可微分汉明损失

reactjs - Jest 测试无法使用 create react app 和 craco 导入铯

r - R : how to find the place of maximum memory us

objective-c - 无法编译使用 Objective-C 包的 Swift 包