initAds method

Future<void> initAds({
  1. bool? hasOpenAd,
})

Implementation

Future<void> initAds({
  bool? hasOpenAd,
}) async {
  _hasOpenAd = hasOpenAd ?? false;

  AdIdInterfaceStore.instance.setadIdInterface = _adId;

  await MobileAds.instance.initialize().then((value) async {
    await MobileAds.instance.updateRequestConfiguration(
      RequestConfiguration(
        testDeviceIds: [],
      ),
    );
  });

  if (hasOpenAd ?? false) {
    await AppOpenAd.load(
      adUnitId: _adId.appOpenId,
      request: AdRequest(),
      adLoadCallback: AppOpenAdLoadCallback(
        onAdLoaded: (AppOpenAd ad) async {
          _appOpenAd = ad;
          appOpenAdCompleter.complete(ad);
        },
        onAdFailedToLoad: (LoadAdError error) {
          print('AppOpenAd failed to load: $error');
        },
      ),
      orientation: 1,
    );
  }
  _preloadAd();
}