In an article I read before, when showing interstitial ad, it was stated that the ad must be shown first and then the transition must be made.
I set ad impressions by number of clicks. Is the code I wrote correct or is there a main usage condition.
I tried two methods and I'm not sure if they are the right methods or not.
Ad controller
class AdController extends GetxController {
InterstitialAd? interstitialAd;
int adCounter = 0;
void onAdLoaded(InterstitialAd ad) {
interstitialAd = ad;
interstitialAd?.fullScreenContentCallback = FullScreenContentCallback(
onAdDismissedFullScreenContent: (ad) {
interstitialAd?.dispose();
initAd();
},
onAdFailedToShowFullScreenContent: (ad, error) {
interstitialAd?.dispose();
initAd();
},
);
}
void initAd() {
InterstitialAd.load(
adUnitId: AdHelper.interstitialAdUnitId,
request: const AdRequest(),
adLoadCallback: InterstitialAdLoadCallback(
onAdLoaded: onAdLoaded,
onAdFailedToLoad: (error) {},
),
);
}
void getAd() {
if (adCounter % 15 == 0) {
interstitialAd?.show();
}
adCounter++;
}
@override
void onInit() {
initAd();
super.onInit();
}
}
First Way
GestureDetector(
onTap: () {
gDealsAdController.getAd();
Get.to(
const GameDealsIndex(),
transition: Transition.native,
duration: const Duration(milliseconds: 200),
arguments: gDeals,);})
Second Way
child: GestureDetector(
onTap: () async {
//todo:
//gDealsAdController.getAd();
//todo: ads try
if (gDealsAdController.adCounter % 10 == 0) {
await gDealsAdController.interstitialAd?.show();
}
gDealsAdController.adCounter++;
Get.to(
const GameDealsIndex(),
transition: Transition.native,
duration: const Duration(milliseconds: 200),
arguments: gDeals,
);