showAdBasedOnName static method
void
showAdBasedOnName(
- BuildContext context, {
- AdModuleWithCallBacks? adModuleWithCallBacks,
- String route = "default",
Implementation
static void showAdBasedOnName(BuildContext context,
{AdModuleWithCallBacks? adModuleWithCallBacks,
String route = "default"}) {
if (GlobalAdVariables.isPremiumUser) {
if (adModuleWithCallBacks != null) {
if (adModuleWithCallBacks.onCloseEvent != null) {
adModuleWithCallBacks.onCloseEvent!();
}
}
return;
}
if (!GlobalAdVariables.globalAdFlag) {
if (adModuleWithCallBacks != null) {
if (adModuleWithCallBacks.onCloseEvent != null) {
GlobalAdVariables().adLoader.value = false;
adModuleWithCallBacks.onCloseEvent!();
}
}
return;
}
final currentRoute = route;
log("MultiAds:[RouteManager]->[current]->$currentRoute");
AdConfigDataModel adConfig =
GlobalAdVariables.screenAdJson?[currentRoute] ??
GlobalAdVariables.screenAdJson!["default"]!;
if (GlobalAdVariables.screenAdJson?[currentRoute] == null) {
log("MultiAds:[AdManager]->[current]->default->${adConfig.toString()}");
} else {
log("MultiAds:[AdManager]->[current]->present->${adConfig.toString()}");
}
if (adConfig.showAds) {
log("MultiAds:[showAdBasedOnScreen]->Ads Turned On");
log("MultiAds:[showAdBasedOnScreen]->Tap->${adConfig.tap}");
final n = (adConfig.tap ??
[])[GlobalAdVariables().getIndex(route: currentRoute)]
.toString();
log("MultiAds:[showAdBasedOnScreen]->CurrentAd->$n");
final (network, ad) = NetworkToIndexMapper.getNetworkFromDoubleString(n);
log("MultiAds:[showAdBasedOnScreen]->CurrentAdNetwork->${network.name}");
log("MultiAds:[showAdBasedOnScreen]->CurrentAdType->${ad.name}");
GlobalAdVariables().adLoader.value = true;
AdClass.showAd(
networkType: network,
adsType: ad,
adModuleWithCallBacks: AdModuleWithCallBacks(
onCloseEvent: () {
GlobalAdVariables().adLoader.value = false;
final p = GlobalAdVariables().increment(
(adConfig.tap ?? []).length - 1,
route: currentRoute);
log("MultiAds:[showAdBasedOnScreen]->Incremented->${p}");
if (adModuleWithCallBacks != null) {
if (adModuleWithCallBacks.onCloseEvent != null) {
adModuleWithCallBacks.onCloseEvent!();
}
}
},
onRewardSkip: adModuleWithCallBacks?.onRewardSkip,
onLoadFailed: () {
log("MultiAds:[showAdBasedOnScreen]->Failed To Load ❌");
showOnFailed(context,
failedFrom: n, adModuleWithCallBacks: adModuleWithCallBacks);
},
onFailed: () {
log("MultiAds:[showAdBasedOnScreen]->Failed ❌");
showOnFailed(context,
failedFrom: n, adModuleWithCallBacks: adModuleWithCallBacks);
},
onAdStarted: adModuleWithCallBacks?.onAdStarted,
onAdLoaded: adModuleWithCallBacks?.onAdLoaded,
),
);
return;
}
if (adModuleWithCallBacks != null) {
if (adModuleWithCallBacks.onCloseEvent != null) {
adModuleWithCallBacks.onCloseEvent!();
}
}
}