Admob's test ads or normal ads not showing on my flutter app. My ad requests return this error: 'Ad failed to load: 3'. I search this error code and found it:
The ad request was successful, but no ad was returned due to lack of ad inventory.
Constant Value: 3
But not only my ads, test ads also don't show. I use the google_mobile_ads package. Here's my codes:
main() at main.dart:
void main() {
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
runApp(MyApp());
}
This variables at my main screen's state class (it is a stateful widget)
BannerAd _ad;
bool isLoaded = false;
The screen's initState function
void initState() {
_ad = BannerAd(
adUnitId: BannerAd.testAdUnitId,
request: AdRequest(),
size: AdSize.banner,
listener: AdListener(
onAdLoaded: (_) {
print("loaded");
setState(() {
isLoaded = true;
});
},
onAdFailedToLoad: (ad, error) {
print("error: $error");
ad.dispose();
},
));
_ad.load();
super.initState();
}
This condition is at bottom of main column
if (isLoaded)
Container(
width: _ad.size.width.toDouble(),
height: _ad.size.height.toDouble(),
child: AdWidget(ad: _ad),
),
Dispose method
void dispose() {
_ad?.dispose();
super.dispose();
}
And related part of the android/app/src/main/AndroidManifests.xml file
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
</application>
I experienced the same problem in my app since a few days. Seams to be a general problem, the example project provided by the package is failing too.
Issue is open #217