如何解决Flutter Google Ads for iOS 在 ListView 中显示 NativeAd 的临时插页式广告
我已迁移到 Flutter 中的新 Google 移动广告包。我的插页式广告效果很好,但我的原生广告在加载到我的 ListView 容器之前在我的大部分屏幕上显示一个临时广告,等待它与 FutureBuilder。如果我继续滚动它最终会根据需要显示。我不确定这是否只是模拟器的问题和我的代码的更大问题。这是问题的一个示例...另外,我不确定它是否是我的 xib 文件,但我使用的是 googleads-moble-flutter/NativeAds 示例中的 1 HERE
这是我的代码示例....
Future futureAd;
@override
void initState() {
super.initState();
futureAd = adBuilder();
}
Future adBuilder() async {
// TODO: Create a NativeAd instance
final myAd = NativeAd(
adUnitId: NativeAd.testAdId,factoryId: 'listTile',request: AdRequest(keywords: ['kpop','music','youth']),listener: AdListener(
onAdLoaded: (_) {
setState(() {
_isAdLoaded = true;
});
},onAdFailedToLoad: (ad,error) {
// Releases an ad resource when it fails to load
ad.dispose();
setState(() {
_isAdLoaded = false;
});
print(
'NATIVE AD ERROR ---- Ad load failed (code=${error.code} message=${error.message})');
},),);
_ad = myAd;
_ad.load();
print(_isAdLoaded);
}
FutureBuilder(
future: futureAd,// ignore: missing_return
builder: (context,snapshot) {
switch (snapshot.connectionState) {
case (ConnectionState.none):
return Container();
case (ConnectionState.done):
return Container(
height: 300,width:
MediaQuery.of(context).size.width,decoration: BoxDecoration(
color: Colors.amberAccent,borderRadius:
BorderRadius.circular(20),boxShadow: [
BoxShadow(
color: Colors.grey,blurRadius: 15,offset: Offset(
4,8),// Shadow position
),],child: (_isAdLoaded = true) ? AdWidget(ad: _ad) :
Image.asset('assets/loading.gif'),);
case (ConnectionState.active):
return Container(
height: 300,width: MediaQuery.of(context).size.width,child: Image.asset('assets/loading.gif')
);
case (ConnectionState.waiting):
return Container(
height: 300,child: Image.asset('assets/loading.gif')
);
default:
return Container(
height: 300,child: Image.asset('logo500.jpeg')
);
}
},
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。