setBannerAd method

Future<bool> setBannerAd({
  1. String? adUnitId,
  2. AdRequest? targetInfo,
  3. List<String>? keywords,
  4. String? contentUrl,
  5. bool? childDirected,
  6. List<String>? testDevices,
  7. bool? nonPersonalizedAds,
  8. bool? testing,
  9. MobileAdListener? listener,
  10. AdSize? size,
  11. double? anchorOffset,
  12. double? horizontalCenterOffset,
  13. AdErrorListener? errorListener,
})

Set the Banner Ad options.

Implementation

Future<bool> setBannerAd({
  String? adUnitId,
  AdRequest? targetInfo,
  List<String>? keywords,
  String? contentUrl,
  bool? childDirected,
  List<String>? testDevices,
  bool? nonPersonalizedAds,
  bool? testing,
  m.MobileAdListener? listener,
  AdSize? size,
  double? anchorOffset,
  double? horizontalCenterOffset,
//    AnchorType anchorType,
  m.AdErrorListener? errorListener,
}) {
  // Can only have one instantiated Ads object.
  if (!_firstObject) {
    return Future.value(false);
  }

  if (listener != null) {
    banner.eventListeners.add(listener);
  }

  _bannerAd ??= Banner(listener: banner);

  banner.loadedListener = () {
    bannerCompleter.complete(_bannerAd!._banner.ad as BannerAd);
  };

  banner.failedListener = (Ad ad, LoadAdError error) {
//        completer.completeError(error);
  };

  if (adUnitId == null || adUnitId.isEmpty || adUnitId.length < 30) {
    adUnitId = _bannerUnitId;
  }

  return _bannerAd!.set(
    adUnitId: adUnitId,
    targetInfo: targetInfo,
    keywords: keywords ?? _keywords,
    contentUrl: contentUrl ?? _contentUrl,
    childDirected: childDirected ?? _childDirected,
    testDevices: testDevices ?? _testDevices,
    nonPersonalizedAds: nonPersonalizedAds ?? _nonPersonalizedAds,
    testing: testing ?? _testing,
    size: size ?? _size,
    anchorOffset: anchorOffset ?? _anchorOffset,
    horizontalCenterOffset: horizontalCenterOffset ?? _horizontalCenterOffset,
//      anchorType: anchorType ?? _anchorType,
    errorListener: errorListener ?? _errorListener,
  );
}