flutter - 使用 Admob 处理多个原生广告
问题描述
我正在为我的 Flutter 应用程序使用 google_mobile_ads。
根据 Google Flutter 提供的参考资料,我如何在 ListView 中有多个原生广告(https://codelabs.developers.google.com/codelabs/admob-inline-ads-in-flutter#1)。
提供的示例仅允许在 ListView 中显示 1 个原生广告。我的目的是为同一个 ListView 中的不同条目显示不同的广告。
解决方案
我发现使用flutter_native_admob
package更容易
你应该使用ListView.seprated
. 试试下面的代码。
ListView.separated(
shrinkWrap: true,
physics: const AlwaysScrollableScrollPhysics(),
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return Center(
child: Text("List Item")
);
},
separatorBuilder: (BuildContext context, index) {
return Container(
child: NativeAdmob(
adUnitID: ***your ad unit ID***,
controller: _nativeAdController,
type: NativeAdmobType.full,
loading: Center(
child: CircularProgressIndicator(),
),
error: Center(
child: Text(
"Ad failed to load"
),
),
),
height: MediaQuery.of(context).size.height*(30/100),
padding: EdgeInsets.all(8),
);
},
);
这样,您将在每个列表项之后获得原生广告。
推荐阅读
- ionic-framework - 在离子中离开当前页面时如何关闭模式
- amazon-ec2 - AWS EC2 实例中有多少个节点?
- c# - 使用正则表达式从电子邮件 HTML 中捕获某些内容
- c# - EF Core 创建一个不存在的字段
- angular - 为什么点击事件即使被删除也会触发?
- macos - MacOs - 解压大量 .gz 文件
- c++ - lambda 表达式的执行策略问题
- python - 在 Windows Server 2012 上运行 Flask 站点的 EC2 Windows Server 上执行 Selenium 脚本
- java - FileProvider IllegalArgumentException
- sql - SQL查询计数相同的值并在单独的列中显示值