Bru*_*uno 3 admob dart flutter
原生广告是我显示的一个错误。我使用来自 google 的测试广告 ID。
“此广告可能尚未加载或已被处置。找不到具有以下 ID 的广告:1”
谁能帮我?
编辑 #1 我的代码 原生广告有不同的示例代码吗?我使用 google_mobile_ads:^0.13.2
...
class _GameState extends State<Game> {
static const AdRequest targetingInfo = AdRequest(
);
static const int maxFailedLoadAttempts = 3;
static const _adUnitIDNative = "ca-app-pub-3940256099942544/2247696110";
late StreamSubscription _subscription;
bool? _deutsch;
final NativeAd myNative = NativeAd(
adUnitId: _adUnitIDNative,
factoryId: 'listTile',
request: AdRequest(),
listener: NativeAdListener(),
);
final NativeAdListener listener = NativeAdListener(
// Called when an ad is successfully received.
onAdLoaded: (Ad ad) => print('Ad loaded.'),
// Called when an ad request failed.
onAdFailedToLoad: (Ad ad, LoadAdError error) {
// Dispose the ad here to free resources.
ad.dispose();
print('NativeAd failed to load: $error');
},
// Called when an ad opens an overlay that covers the screen.
onAdOpened: (Ad ad) => print('Ad opened.'),
// Called when an ad removes an overlay that covers the screen.
onAdClosed: (Ad ad) => print('Ad closed.'),
// Called when an impression occurs on the ad.
onAdImpression: (Ad ad) => print('Ad impression.'),
// Called when a click is recorded for a NativeAd.
onNativeAdClicked: (NativeAd ad) => print('Ad clicked.'),
);
get adContainer => null;
@override
void initState() {
super.initState();
_createInterstitialAd();
myNative.load();
}
Run Code Online (Sandbox Code Playgroud)
...
Container(
alignment: Alignment.center,
child: AdWidget(ad: myNative),
padding: EdgeInsets.all(10),
margin: EdgeInsets.only(bottom: 20.0),
height: 70,
),
Run Code Online (Sandbox Code Playgroud)
谢谢
Mic*_*ran 12
您的 AdWidget 正在广告加载完成之前构建;你需要实现三件事:
// 1. Create bool
bool isAdLoaded = false;
// 2. Add listener event
final NativeAdListener listener = NativeAdListener(
// Called when an ad is successfully received.
onAdLoaded: (Ad ad) => {
setState(() {
isAdLoaded = true;
});
...
// 3. Wrap the AdWidget inside a switch
isAdLoaded ? Container(
alignment: Alignment.center,
child: AdWidget(ad: myNative),
padding: EdgeInsets.all(10),
margin: EdgeInsets.only(bottom: 20.0),
height: 70,
) : CircularProgressIndicator(),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1574 次 |
| 最近记录: |