loadAd method
Future<bool>
loadAd(
{ - required bool show,
- String? adUnitId,
- AdRequest? targetInfo,
- List<String>? keywords,
- String? contentUrl,
- bool? childDirected,
- List<String>? testDevices,
- bool? nonPersonalizedAds,
- bool? testing,
- double? anchorOffset,
- 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;
}