flutterflutter-packagesgoogle-mobile-ads

Showing Interstitial ads every 5 clicks


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