loadBannerCollapsible static method

void loadBannerCollapsible(
  1. BuildContext context,
  2. BannerHolder bannerHolder,
  3. BannerCollapsibleType type
)

Implementation

static void loadBannerCollapsible(BuildContext context,
    BannerHolder bannerHolder, BannerCollapsibleType type) async {
  if (!_isShowAds || await isNetworkConnected() == false) {
    bannerHolder.isLoad = false;
    bannerHolder.adsBannerController.value = Banner(null, "no internet");
    return;
  }

  final String adUnitId = _isDebug
      ? _idTestBannerCollapsibleAd
      : Platform.isAndroid
          ? bannerHolder.idAndroid
          : bannerHolder.idIOS;

  if (!context.mounted) {
    return;
  }

  final size = await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
      MediaQuery.sizeOf(context).width.truncate());

  if (size == null) {
    // Unable to get the size.
    return;
  }

  bannerHolder.isLoad = true;
  bannerHolder.adsBannerController.value = Banner(null, "");

  // Create an extra parameter that aligns the bottom of the expanded ad to the
  // bottom of the banner ad.
  var adRequest = AdRequest(extras: {
    "collapsible":
        (type == BannerCollapsibleType.COLLAPSIBLE_BOTTOM) ? "bottom" : "top",
  });

  BannerAd(
      adUnitId: adUnitId,
      request: adRequest,
      size: size,
      listener: BannerAdListener(
        onAdLoaded: (ad) {
          log("message load banner collap  $ad");
          bannerHolder.adsBannerController.value =
              Banner(ad as BannerAd, "success");
        },
        onAdFailedToLoad: (ad, err) {
          log("message load banner collap err: $err");
          bannerHolder.isLoad = false;
          bannerHolder.adsBannerController.value =
              Banner(ad as BannerAd, "error");
          ad.dispose();
        },
      )).load();
}