loadAndShowNativeWithLayout static method

void loadAndShowNativeWithLayout(
  1. BuildContext context,
  2. NativeHolder nativeHolder,
  3. NativeAdmobType nativeType
)

Implementation

static void loadAndShowNativeWithLayout(BuildContext context,
    NativeHolder nativeHolder, NativeAdmobType nativeType) async {
  if (!_isShowAds || await isNetworkConnected() == false) {
    isLoad = false;
    adsNativeController.value = Pair(null, "no internet");
    return;
  }

  final String adUnitId = _isDebug
      ? _idTestNativeAd
      : Platform.isAndroid
          ? nativeHolder.idAndroid
          : nativeHolder.idIOS;

  if (!context.mounted) {
    return;
  }
  adsNativeController.value.nativeAd?.dispose();
  isLoad = true;
  adsNativeController.value = Pair(null, "");
  NativeAd(
    adUnitId: adUnitId,
    factoryId: (nativeType == NativeAdmobType.NATIVE_MEDIUM)
        ? 'NativeCustomMedium'
        : 'NativeCustomSmall',
    listener: NativeAdListener(
      onAdLoaded: (ad) {
        log("TAG==== onAdLoaded ${ad.responseInfo}");
        adsNativeController.value = Pair(ad as NativeAd, "success");
      },
      onAdFailedToLoad: (ad, error) {
        log("TAG==== onAdFailedToLoad ${ad.responseInfo}");
        isLoad = false;
        adsNativeController.value = Pair(ad as NativeAd, "error");
        ad.dispose();
      },
      // Called when a click is recorded for a NativeAd.
      onAdClicked: (ad) {},
      // Called when an impression occurs on the ad.
      onAdImpression: (ad) {},
      // Called when an ad removes an overlay that covers the screen.
      onAdClosed: (ad) {},
      // Called when an ad opens an overlay that covers the screen.
      onAdOpened: (ad) {},
      // For iOS only. Called before dismissing a full screen view
      onAdWillDismissScreen: (ad) {},
      // Called when an ad receives revenue value.
      onPaidEvent: (ad, valueMicros, precision, currencyCode) {},
    ),
    request: const AdRequest(),
  ).load();
}