Since you've not provided any code, I'd assume and answer based on how I think you can do it.
If you're displaying the ad in predefined fixed locations, you'd need to create a new BannerAd
for each location. You'd also have to individually load these BannerAd
s like so:
final BannerAd myBanner1 = BannerAd(
adUnitId: '<Banner ID>',
size: AdSize.smartBanner,
request: AdRequest(),
listener: AdListener(onAdClosed: (ad) => ad.dispose()),
);
myBanner1.load();
final adWidget1 = AdWidget(ad: myBanner1);
...
...
...
final BannerAd myBannerNth = BannerAd(
adUnitId: '<Banner ID>',
size: AdSize.banner,
request: AdRequest(),
listener: AdListener(onAdClosed: (ad) => ad.dispose()),
);
myBannerNth.load();
final adWidgetNth = AdWidget(ad: myBannerNth);
Where myBannerNth/adWidgetNth is the nth banner/ad widget.
For dynamic, auto-generated situations such as in a ListView.separated
, you could do it like so:
// Defined somewhere, e.g. in your State[less/ful] widget
Map<String, BannerAd> ads = <String, BannerAd>{};
...
...
...
ListView.separated(
separatorBuilder: (context, index) => Divider(),
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
ads['myBanner$index'] = BannerAd(
adUnitId: '<Banner ID>',
size: AdSize.banner,
request: AdRequest(),
listener: AdListener(onAdClosed: (ad) => ad.dispose()));
ads['myBanner$index'].load();
if (index % 6 == 0) {
return Column(
children: [
Container(
child: AdWidget(ad: ads['myBanner$index']),
height: 100.0,
),
_buildItem(context, items[index])
],
);
}
return _buildItem(context, items[index]);
},
itemCount: items.length,
)
Where ads
is a Map
whose values are the individual dynamically auto-generated banner ads.