Showing Interstitial ads every 5 clicks

Issue

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();
                    }
                 }
              );
           },

Solution

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;
      }
    });
  }),

Answered By – eshanz7

Answer Checked By – Jay B. (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *