【问题标题】:Flutter with multiple Native Ad using Admob使用 Admob 处理多个原生广告
【发布时间】:2021-08-18 01:32:12
【问题描述】:

我正在为我的 Flutter 应用使用 google_mobile_ads。

根据 Google Flutter 提供的参考资料,如何在 ListView (https://codelabs.developers.google.com/codelabs/admob-inline-ads-in-flutter#1) 中有多个 Native Ads。

提供的示例仅允许在 ListView 中显示 1 个原生广告。我的目的是为同一个 ListView 中的不同条目显示不同的广告。

【问题讨论】:

    标签: flutter googlemobileads


    【解决方案1】:

    我发现使用 flutter_native_admob 包更容易

    您应该使用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),
                              );
                            },
                          );
    

    这样您将在每个列表项之后获得原生广告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      • 2018-07-09
      • 2020-07-11
      • 2016-10-29
      • 2016-10-30
      • 2016-09-06
      • 2020-12-17
      相关资源
      最近更新 更多