admob_flutter icon indicating copy to clipboard operation
admob_flutter copied to clipboard

Ability to preload banner ads

Open chris-rutkowski opened this issue 4 years ago • 1 comments

Hello, even in your example in README, a banner is in a Scrollable View. I would like to request a feature to preload banner before showing it.

Ideally, my implementation would look like this:

MyUtilityClass.dart

class MyUtilityClass {
  AdmobBannerAd bannerAd;
  bool isBannerAdReady = false;

  void _loadBannerAd() {
    isBannerAdReady = false;
    final cleanup = () {
      bannerAd.dispose();
      bannerAd = null;
    };

    bannerAd = AdmobBannerAd(
      adUnitId: myBannerAdID,
      adSize: AdmobBannerSize.MEDIUM_RECTANGLE,
      listener: (event, _) async {
        if (event == AdmobAdEvent.failedToLoad) {
          cleanup();
          await Future.delayed(Duration(seconds: 1));
          _loadBannerAd();
        } else if (event == AdmobAdEvent.closed) {
          cleanup();
          _loadBannerAd();
        } else if (event == AdmobAdEvent.loaded) {
          isBannerAdReady = true;
        } else {
          ... some other logic
        }
      },
    );
    bannerAd.load();
  }
}

and in some class responsible for generating ListView content I check if isBannerAdReady == true and display like this:

      AdmobBanner(
        ad: Provider.of<MyUtilityClass>(context, listen: false).bannerAd,
      )

This gives us several benefits:

  • separating logic from UI
  • ability to make sure that banners are immediately visible when scrolled onto the screen.

I would appreciate if you check my app 📲 https://well-spoken.app . After completing the tutorial, visit Learn mode again, if you scroll a bit, you will often see empty white boxes that turn into banners after a while. If I have already preloaded instance this glitch would be fixed.

Appreciate help, and keep up good work :)

chris-rutkowski avatar Nov 05 '20 01:11 chris-rutkowski

Don't use admob_flutter. Just use firebase_admob, and it is reliable.

it-one-mm avatar Jan 11 '21 13:01 it-one-mm