【问题标题】:How to wait interstitial ad with waiting dialog in flutter如何在颤动中等待带有等待对话框的插页式广告
【发布时间】:2019-03-28 12:25:00
【问题描述】:

Here 是一篇文章,它说您不应该使用插页式广告给用户带来惊喜。

我有这样的代码可以在广告出现之前延迟它:

void _onLoading() {
showDialog(
    context: context,
    barrierDismissible: false,
    builder: (context) => AlertDialog(
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(32.0))),
          contentPadding: EdgeInsets.only(top: 10.0),
          content: Container(
            margin: const EdgeInsets.all(10.0),

              child: new Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  new CircularProgressIndicator(),
                  SizedBox(width: 16.0),
                  new Text("Please wait.."),
                ],
              )),
        ));

new Future.delayed(new Duration(seconds: 3), () {
  Navigator.pop(context); //pop dialog
  createInterstitialAd()
    ..load()
    ..show();
});}

但该代码仅等待 3 秒,并且不依赖于插页式广告何时出现。在这种情况下,如果 3 秒后连接仍然很慢,它将保持沉默。在插页式广告真正出现之前,我该如何处理。 谢谢。

【问题讨论】:

  • 好主意是在应用打开时加载插页式广告,当您需要显示广告时,检查广告是否已加载,如果是,请继续显示,否则再次加载并下次加载当有趣的事件发生时展示它。
  • 是的,这是一个逻辑......谢谢,但是,如何处理它的颤振代码?还是未来延迟取决于插页式广告的出现?
  • 对不起,我没有找到你,你为什么需要FutureDelayed
  • 是的,也许是一些类似的颤动代码等到插页式广告出现
  • 我不明白您需要使用Future.delayed(),只需在应用启动时加载广告,并在您发生有趣的操作(例如用户转到新页面)时显示它。

标签: flutter dialog admob interstitial


【解决方案1】:

我在我的代码中使用它:

InterstitialAd myInterstitialAd = InterstitialAd(
        adUnitId: <youradUnitId>,
        targetingInfo: MobileAdTargetingInfo(
          childDirected: true,
          nonPersonalizedAds: true,
        ),
        listener: (event) {
          if (event == MobileAdEvent.opened || event == MobileAdEvent.failedToLoad) {
            <go to another page>
          }
        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多