fetchAd method
void
fetchAd()
Fetches an ad in the background.
Implementation
void fetchAd() {
_completer = Completer<ResponseBanner>();
if (kIsWeb == true) {
_completer.complete(ResponseBanner(StatusBanner.notLoadedOnWeb));
_log('Aborted loading BannerAd: ads not available on the web');
} else {
// no await
BannerAd(
adUnitId: _adUnitId,
size: AdSize.banner,
request: const AdRequest(),
listener: BannerAdListener(
onAdLoaded: (ad) {
_completer.complete(
ResponseBanner(StatusBanner.loadedSuccess, ad: ad as BannerAd));
_log('BannerAd loaded');
},
onAdFailedToLoad: (ad, error) {
ad.dispose();
_completer.complete(ResponseBanner(StatusBanner.notLoadedGenerally,
admobErrorCode: error.code, admobErrorMessage: error.message));
_log('BannerAd failed to load: ${error.code} ${error.message}');
},
),
).load();
}
}