即使在使用 ..load() 后,广告也未在 Flutter (google_mobile_ads) 中加载

时间:2021-06-22 07:27:08

标签: flutter dart admob ads

我正在尝试在我的 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),
        ),

0 个答案:

没有答案