简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM