Google Admob Ad not showing
I am trying to implement Google Ads into my flutter app. I closely followed the implementation guides but when I start the app even though it says the ad successfully loaded it does not show up. Sometimes it flashes up for a second but immediately disappears afterwords. Does anyone have an idea what could be the problem?
loadAd() { BannerAd banner = BannerAd( adUnitId: adUnitId, request: AdRequest(), size: AdSize.banner, listener: BannerAdListener( // Called when an ad is successfully received. onAdLoaded: (ad) { debugPrint('$ad loaded.'); setState(() { _isLoaded = true; }); }, // Called when an ad request failed. onAdFailedToLoad: (ad, err) { debugPrint('BannerAd failed to load: $err'); // Dispose the ad here to free resources. ad.dispose(); }, ) ); banner.load(); setState(() { _bannerAd = banner; }); }
Widget build(BuildContext context) { return _isLoaded ? Container() : Container( alignment: Alignment.center, child: SizedBox( height: AdSize.banner.height.toDouble(), width: AdSize.banner.width.toDouble(), child: AdWidget( ad: _bannerAd!, ), ), ); }