loadAd method

Future<bool> loadAd({
  1. required bool show,
  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. double? anchorOffset,
  11. double? horizontalCenterOffset,
})

Implementation

Future<bool> loadAd({
  required bool show,
  String? adUnitId,
  g.AdRequest? targetInfo,
  List<String>? keywords,
  String? contentUrl,
  bool? childDirected,
  List<String>? testDevices,
  bool? nonPersonalizedAds,
  bool? testing,
  double? anchorOffset,
  double? horizontalCenterOffset,
//    AnchorType anchorType,
}) async {
  // Are we testing?
  testing ??= _testing;

  // Supply a valid unit id.
  if (adUnitId == null || adUnitId.isEmpty || adUnitId.length < 30) {
    adUnitId = _adUnitId;
  }

  targetInfo ??= _targetInfo(
    keywords: keywords,
    contentUrl: contentUrl,
    testDevices: testDevices,
    nonPersonalizedAds: nonPersonalizedAds,
  );

  // Save the info. into a class property.
  _adRequest = targetInfo;

  // Get rid of the ad if already created.
  await dispose();

  // Create the ad.
  _ad ??=
      _createAd(testing: testing, adUnitId: adUnitId, targetInfo: targetInfo);

  try {
    await _ad?.load();
    loaded = true;
  } catch (ex) {
    loaded = false;
    _setError(ex);
  }
  // Load the ad in memory.
  return loaded;
}