Dani
Dani

Reputation: 4186

Interstitial ads not showing in Flutter

I'm using this package: https://pub.dev/packages/firebase_admob

Everything is setup correctly and the normal banner is showing. My problem comes only with the interstitial one:

import 'package:firebase_admob/firebase_admob.dart';

BannerAd myBanner = BannerAd(
  adUnitId: BannerAd.testAdUnitId,
  size: AdSize.smartBanner,
  listener: (MobileAdEvent event) {
    print("BannerAd event is $event");
  },
);

InterstitialAd myInterstitial = InterstitialAd(
  adUnitId: 'ca-app-pub-MYID',
  listener: (MobileAdEvent event) {
    print("InterstitialAd event is $event");
  },
);

class Ads {
  static showBanner() {
    myBanner
      // typically this happens well before the ad is shown
      ..load()
      ..show(
        // Positions the banner ad 60 pixels from the bottom of the screen
        anchorOffset: 0.0,
        // Positions the banner ad 10 pixels from the center of the screen to the right
        horizontalCenterOffset: 0.0,
        // Banner Position
        anchorType: AnchorType.bottom,
      );
  }

  static showInterstitial() {
    myInterstitial
      ..load()
      ..show(
        anchorType: AnchorType.bottom,
        anchorOffset: 0.0,
        horizontalCenterOffset: 0.0,
      );
  }
}

final Ads ads = Ads();

To show it I do: Ads.showInterstitial(); but it's never shown.

If I try to call it again the error breaks the app.

I do not use Statefull widgets on my app

Upvotes: 1

Views: 2250

Answers (1)

korchix
korchix

Reputation: 1700

i think you have to add the ID of your device, as testDevice to be able to see the ads there.

add a targetingInfo property, where you add the ID of your device.

MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
  testDevices: <String>["*add id of your device here*"], // Android emulators are considered test devices
);

and when creating your Interstitial field, add the targetingInfo property, like mentioned in the Readme of the plugin page.

InterstitialAd myInterstitial = InterstitialAd(
  // Replace the testAdUnitId with an ad unit id from the AdMob dash.
  // https://developers.google.com/admob/android/test-ads
  // https://developers.google.com/admob/ios/test-ads
  adUnitId: InterstitialAd.testAdUnitId,
  targetingInfo: targetingInfo, // <--- here
  listener: (MobileAdEvent event) {
    print("InterstitialAd event is $event");
  },
);

Upvotes: 1

Related Questions