admob_flutter
admob_flutter copied to clipboard
Ability to preload banner ads
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 :)
Don't use admob_flutter. Just use firebase_admob, and it is reliable.