我正在尝试向我的应用添加横幅广告。我希望横幅显示在我的应用程序的某些页面上,但是一旦您到达某些页面,我希望横幅消失。所以我让我的横幅出现并且它正在工作。我还发现使用
super.dispose();
myBanner?.dispose();
Run Code Online (Sandbox Code Playgroud)
在我的 onPressed 按钮上将摆脱横幅。但是,当我弹回加载横幅的页面时,出现错误:
I/flutter (7058): 处理手势时抛出以下断言:I/flutter (7058): 'package:firebase_admob/firebase_admob.dart': Failed assertion: line 227 pos 12: '_allAds[id] != I /flutter ( 7058): null': 不是真的。
然后我无法点击任何在 onPressed 上有我处置的按钮。
我试过添加 super.dispose() 因为我只有 myBanner?.dispose(); 之前,但结果是一样的。我无法找到有关 admob 的大量信息。
这是我设置横幅的方法:
BannerAd myBanner = BannerAd(
// Replace the testAdUnitId with an ad unit id from the AdMob dash.
// https://developers.google.com/admob/android/test-ads
// https://developers.google.com/admob/ios/test-ads
adUnitId: adUnitId,
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event is $event");
},
);
Run Code Online (Sandbox Code Playgroud)
然后在我的课上:
class EnMainMenu extends StatefulWidget {
@override …Run Code Online (Sandbox Code Playgroud)