如何在插页式广告对话框中等待插页式广告

时间:2019-03-28 12:25:00

标签: flutter dialog admob interstitial

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秒钟后连接仍然很慢,它将保持静音。在插页广告真正出现之前,我该如何处理。 谢谢。

1 个答案:

答案 0 :(得分:0)

我在我的代码中使用它:

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