我正在尝试在我的 Flutter 应用中添加横幅广告 但是即使我添加了 ..load()
广告也没有加载这是我在控制台中得到的
AdWidget requires Ad.load to be called before AdWidget is inserted into the tree
I/flutter (12791):广告展示。
I/flutter (12791):已加载广告。
void didChangeDependencies() {
super.didChangeDependencies();
final adState = Provider.of<AdState>(context);
adState.initialization.then((status) {
setState(() {
banner = BannerAd(
adUnitId: adState.bannerAdUnitId,
size: AdSize.smartBannerLandscape,
request: AdRequest(),
listener: BannerAdListener(
onAdLoaded: (Ad ad) => print('Ad loaded.'),
onAdFailedToLoad: (Ad ad, LoadAdError error) {
ad.dispose();
print('Ad failed to load: $error');
},
onAdOpened: (Ad ad) => print('Ad opened.'),
onAdClosed: (Ad ad) => print('Ad closed.'),
onAdImpression: (Ad ad) => print('Ad impression.'),
)
)..load();
});
});
}
bottomNavigationBar: Container(
height: 50,
child: AdWidget(ad: banner),
),