flutter 如何先通过按钮显示一个插页式广告,然后转到新屏幕?

flutter how to show first an interstitial ad through button and then go to new screen?

我想在 flutter 中加载带有按钮的插页式广告。我想先显示插页式广告,然后在广告结束时自动转到另一个屏幕,或加载其他内容。

我不知道如何制作类似“interstitial.wait”的内容来首先展示广告,然后关闭 运行 另一件事。

这是我的代码:

onPressed: () {
   showInterstitialAd(); //this first
   launch(urlCourse.text); //when ad closed, run this
}

回答我自己的问题。我们可以利用 onAdDismissedFullScreenContent

这是一个例子:

 void showInterstitialAd() {
    if (interstitialAd == null) {
      print('trying to show before loading');
      return;
    }

    interstitialAd!.fullScreenContentCallback = FullScreenContentCallback(
        onAdShowedFullScreenContent: (ad) => print('ad showed $ad'),

        //when ad went closes
        onAdDismissedFullScreenContent: (ad) {
          //run something
          launch(urlCourse.text); 
          ad.dispose();
          createInterstitialAd();
        },
        onAdFailedToShowFullScreenContent: (ad, error) {
          ad.dispose();
          print('failed to show the ad $ad');

          createInterstitialAd();
        });

    interstitialAd!.show();
    interstitialAd = null;
  }