gpt4 book ai didi

flutter - 无法在ListView。分隔的Flutter中展示广告

转载 作者:行者123 更新时间:2023-12-03 03:56:52 24 4
gpt4 key购买 nike

我在flutter中使用firebase_admob,并且想在ListView.separated中显示广告。

     void initState(){
FirebaseAdMob.instance.initialize(appId: 'ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXX');
}


static const MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
keywords: <String>['flutterio', 'beautiful apps'],
contentUrl: 'https://flutter.io',
childDirected: false,
testDevices: <String>[], // Android emulators are considered test devices
);

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: BannerAd.testAdUnitId,
size: AdSize.smartBanner,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("BannerAd event is $event");
},
);

我想在哪里展示广告:
return ListView.separated(
padding: EdgeInsets.zero,
itemCount: data.articles.length,
separatorBuilder: (context, index) {
if (index % 5 == 0) { // Display `AdmobBanner` every 5 'separators'.
return myBanner;
}
return Divider();
},

但是我遇到了这个问题:错误:返回类型'BannerAd'不是由匿名闭包定义的'Widget'。 (来自lib \ src \ ui \ home \ home_screen.dart:445的return_of_invalid_type_from_closure)。

最好的解决方案是什么?

谢谢

最佳答案

尝试使用此非正式的admob plugin flutter 打。

关于flutter - 无法在ListView。分隔的Flutter中展示广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60421276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com