Home > Mobile >  Showing Interstitial ads every 5 clicks
Showing Interstitial ads every 5 clicks

Time:02-14

I have an ElevatedButton to call family member using flutter_phone_direct_caller. I wish to show interstitial ads once every 5 clicks user pushes the ElevatedButton. The code below works fine but after 5 clicks, the interstitial ads show up every time.

  ElevatedButton(
       onPressed: () {
              admobHelper.createInterad();
              callFamilyMember();
                    setState(() {
                        clickCount=clickCount 1;
                        if(clickCount>5){
                        admobHelper.showInterad();
                    }
                 }
              );
           },

CodePudding user response:

Replace your code with this one. you have to set clickcounts to 0 on show ad.

ElevatedButton(onPressed: () {
    admobHelper.createInterad();
    callFamilyMember();
    setState(() {
      clickCount = clickCount   1;
      if (clickCount > 5) {
        admobHelper.showInterad();
        clickCount = 0;
      }
    });
  }),
  • Related