setVideoAd method

Future<bool> setVideoAd({
  1. bool show = false,
  2. String? adUnitId,
  3. AdRequest? targetInfo,
  4. List<String>? keywords,
  5. String? contentUrl,
  6. bool? childDirected,
  7. List<String>? testDevices,
  8. bool? nonPersonalizedAds,
  9. bool? testing,
  10. MobileAdListener? listener,
  11. RewardListener? rewardListener,
  12. AdErrorListener? errorListener,
})

Video Ad

Set the Video Ad options.

Implementation

Future<bool> setVideoAd({
  bool show = false,
  String? adUnitId,
  AdRequest? targetInfo,
  List<String>? keywords,
  String? contentUrl,
  bool? childDirected,
  List<String>? testDevices,
  bool? nonPersonalizedAds,
  bool? testing,
  m.MobileAdListener? listener,
  m.RewardListener? rewardListener,
  m.AdErrorListener? errorListener,
}) {
  // Can only have one instantiated Ads object.
  if (!_firstObject) {
    return Future.value(false);
  }

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

  // Add this listener to the Error Listeners.
  if (errorListener != null) {
    m.eventErrorListeners.add(errorListener);
  }

  _videoAd ??= m.VideoAd(listener: video);

  // Add an Reward function if any.
  if (rewardListener != null) {
    _videoAd!.rewardListener = rewardListener;
  }

  // If an unit id is not provided, it may be available from the constructor.
  if (adUnitId == null || adUnitId.isEmpty || adUnitId.length < 30) {
    adUnitId = _videoUnitId;
  }

  return _videoAd!.set(
    adUnitId: adUnitId,
    targetInfo: targetInfo,
    keywords: keywords ?? _keywords,
    contentUrl: contentUrl ?? _contentUrl,
    childDirected: childDirected ?? _childDirected,
    testDevices: testDevices ?? _testDevices,
    nonPersonalizedAds: nonPersonalizedAds ?? _nonPersonalizedAds,
    testing: testing ?? _testing,
    errorListener: errorListener ?? _errorListener,
  );
}