I have a error with Admob banner in Flutter.
This is my error.
I/flutter (25842): AdWidget requires Ad.load to be called before AdWidget is inserted into the tree
And this is my code about Admob banner
class GoogleAdMob {
static BannerAd loadBannerAd() {
BannerAd banner = BannerAd(
adUnitId: globals.admobAdUnitIdBanner!,
size: AdSize.banner,
request: const AdRequest(),
listener: BannerAdListener(
onAdLoaded: (
Ad ad,
) =>
onAdFailedToLoad: (
Ad ad,
LoadAdError error,
) {
ad.dispose();
onAdOpened: (
Ad ad,
) =>
onAdClosed: (
Ad ad,
) =>
onAdImpression: (
Ad ad,
) =>
),
);
return banner;
}
static Container showBannerAd(
BannerAd banner,
) {
final Container adContainer = Container(
alignment: Alignment.center,
width: banner.size.width.toDouble(),
height: banner.size.height.toDouble(),
child: AdWidget(
ad: banner,
),
);
return adContainer;
}
}
What’s matter about the error?