requestAd method
Requests a native ad with the specified parameters.
Returns the loaded ad view if the ad request is successful within the
timeout, otherwise returns null
.
adUnitID
: The ad unit ID for the requested ad.
keywords
: List of keywords to be used in the ad request.
country
: The user's country for ad targeting.
countryWhiteList
: A list of allowed countries for ad requests.
Implementation
Future<AdWithView?> requestAd(
String adUnitID, {
List<String>? keywords,
String? country,
List<String>? countryWhiteList,
}) async {
if (_canRequestAd(country: country, whiteList: countryWhiteList)) {
final adView = await retry<NativeAd?>(
task: () async => _requestAd(adUnitID, keywords: keywords),
taskTimeout: kFastAdDefaultTimeout,
maxAttempts: 2,
);
if (adView != null) {
_setLimitOnAdRequest();
return adView;
}
}
return null;
}