我正在为我的 Flutter 应用程序使用 google_mobile_ads。
根据 Google Flutter 提供的参考资料,我如何在 ListView 中有多个原生广告(https://codelabs.developers.google.com/codelabs/admob-inline-ads-in-flutter#1)。
提供的示例仅允许在 ListView 中显示 1 个原生广告。我的目的是为同一个 ListView 中的不同条目显示不同的广告。
我正在为我的 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),
);
},
);
这样,您将在每个列表项之后获得原生广告。