showOnFailed static method

void showOnFailed(
  1. BuildContext context, {
  2. AdModuleWithCallBacks? adModuleWithCallBacks,
  3. required String failedFrom,
})

Implementation

static void showOnFailed(
  BuildContext context, {
  AdModuleWithCallBacks? adModuleWithCallBacks,
  required String failedFrom,
}) {
  final currentRoute = RouteMethods().getCurrentRoute(context);
  AdConfigDataModel adConfig =
      GlobalAdVariables.screenAdJson?[currentRoute] ??
          GlobalAdVariables.screenAdJson!["default"]!;
  AdConfigDataModel defaultConfig =
      GlobalAdVariables.screenAdJson!["default"]!;

  //Check Limit Hits 3

  if (limit > 3) {
    log("MultiAds:[showOnFailed]->overflow->case->more than 3");
    limit = 1;
    if (adModuleWithCallBacks != null) {
      if (adModuleWithCallBacks.onCloseEvent != null) {
        GlobalAdVariables().adLoader.value = false;
        adModuleWithCallBacks.onCloseEvent!();
      }
      GlobalAdVariables()
          .increment((adConfig.tap ?? []).length - 1, route: currentRoute);
    }
    return;
  }
  //Check User is Premium
  if (GlobalAdVariables.isPremiumUser) {
    if (adModuleWithCallBacks != null) {
      if (adModuleWithCallBacks.onCloseEvent != null) {
        adModuleWithCallBacks.onCloseEvent!();
      }
    }
    return;
  }
  //Check For Global Call

  if (!GlobalAdVariables.globalAdFlag) {
    if (adModuleWithCallBacks != null) {
      if (adModuleWithCallBacks.onCloseEvent != null) {
        GlobalAdVariables().adLoader.value = false;
        adModuleWithCallBacks.onCloseEvent!();
      }
    }
    return;
  }

  //Execute Te Code

  limit = limit + 1;

  if (adConfig.showAds) {
    final n =
        adConfig.failed![failedFrom] ?? defaultConfig.failed![failedFrom];
    log("MultiAds:[showOnFailed]->load->failedāŒ->$n");
    final (network, ad) = NetworkToIndexMapper.getNetworkFromDoubleString(n);
    AdClass.showAd(
      networkType: network,
      adsType: ad,
      adModuleWithCallBacks: AdModuleWithCallBacks(
        onCloseEvent: () {
          GlobalAdVariables().adLoader.value = false;
          GlobalAdVariables().increment((adConfig.tap ?? []).length - 1,
              route: currentRoute);
          if (adModuleWithCallBacks != null) {
            if (adModuleWithCallBacks.onCloseEvent != null) {
              adModuleWithCallBacks.onCloseEvent!();
            }
          }
        },
        onRewardSkip: adModuleWithCallBacks?.onRewardSkip,
        onLoadFailed: () {
          showOnFailed(
            context,
            failedFrom: n,
            adModuleWithCallBacks: adModuleWithCallBacks,
          );
        },
        onFailed: () {
          showOnFailed(
            context,
            failedFrom: n,
            adModuleWithCallBacks: adModuleWithCallBacks,
          );
        },
        onAdStarted: adModuleWithCallBacks?.onAdStarted,
        onAdLoaded: adModuleWithCallBacks?.onAdLoaded,
      ),
    );
    return;
  }
  if (adModuleWithCallBacks != null) {
    if (adModuleWithCallBacks.onCloseEvent != null) {
      adModuleWithCallBacks.onCloseEvent!();
    }
  }
}