Промежуточные объявления не отображаются во флаттере - PullRequest
1 голос
/ 06 января 2020

Я использую этот пакет: https://pub.dev/packages/firebase_admob

Все настроено правильно, и отображается обычный баннер. Моя проблема приходит только с промежуточной:

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();

Чтобы показать это, я делаю: Ads.showInterstitial();, но он никогда не отображается.

Если я пытаюсь вызвать его снова, ошибка ломает приложение .

Я не использую виджеты Statefull в своем приложении

1 Ответ

0 голосов
/ 28 марта 2020

Я думаю, вам нужно добавить идентификатор вашего устройства, как testDevice, чтобы иметь возможность видеть рекламу там.

добавить свойство targettingInfo, в которое вы добавляете идентификатор своего устройства.

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

и при создании поля Interstitial добавьте свойство targettingInfo, как указано в Readme на странице плагина .

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");
  },
);
...