Show InterstitialAd Before opening link in flutter

92 Views Asked by At

load my ad before performing launchURL.

buttonactionL: () async{
                await StartApp.showInterstitialAd();
                String url = "https://google.com";
                _launchURL(url);
              },
1

There are 1 best solutions below

0
On

Call showAds method and in the completion of onAdClosed and onAdFailedToLoad perform launchURl operation:

  void showAds() {

    _interstitialAd = InterstitialAd(
      adUnitId: AdHelper.interstitialAdUnitId,
      request: AdRequest(),
      listener: AdListener(onAdLoaded: (ad) {
        print("Ad Loaded");
        showAds();
      }, onAdClosed: (ad) {
        print("Closed Ad");
      }, onAdOpened: (ad) {
        print("Opened Ad");
      }, onAdFailedToLoad: (ad, error) {
        print("Failed to load Ad $error");
      }),
    );
    _interstitialAd.load();
  }