initialize method
void
initialize({})
Initializes and resets this service class. In case of disableAds or kIsWeb the initialization will not complete.
It is save to call this method even if user has DENIED the GDPR confirmation dialog. In this case, Admob will refrain from delivering ads.
Implementation
void initialize(
{List<String> bannerIds = const [],
List<String> interstitialIds = const [],
List<String> interRewardIds = const [],
List<String> testDeviceIds = const []}) async {
_bannerMap.clear();
_intertsitialMap.clear();
_interstitialRewardedMap.clear();
if (isDisabledProgrammatically()) {
_isInitialized = false;
return;
}
await MobileAds.instance.initialize();
final old = await MobileAds.instance.getRequestConfiguration();
final cnf = RequestConfiguration(
maxAdContentRating: old.maxAdContentRating,
tagForChildDirectedTreatment: old.tagForChildDirectedTreatment,
tagForUnderAgeOfConsent: old.tagForUnderAgeOfConsent,
testDeviceIds: testDeviceIds);
await MobileAds.instance.updateRequestConfiguration(cnf);
for (String adUnitId in bannerIds) {
final instance = BannerServiceInstance(adUnitId);
instance.fetchAd();
_bannerMap.putIfAbsent(adUnitId, () => instance);
_log('Added bannerId: $adUnitId');
}
for (String adUnitId in interstitialIds) {
final instance = InterstitialServiceInstance(adUnitId);
instance.fetchAd();
_intertsitialMap.putIfAbsent(adUnitId, () => instance);
_log('Added intersitialId: $adUnitId');
}
for (String adUnitId in interRewardIds) {
final instance = RewardedInterstitialInstance(adUnitId);
instance.fetchAd();
_interstitialRewardedMap.putIfAbsent(adUnitId, () => instance);
_log('Added interRewardedId: $adUnitId');
}
_isInitialized = true;
}