I want to put google ads after specific number of items list or in between the items list in ListView.separated
.
I have attached an image to make it clear how I want to do it:
Source of the image is: this article
First, I believe, you need to install a library to display Google AdMob ads. For instance - admob_flutter
lib.
Then you only need to set up the separatorBuilder
property of your ListView.separated
widget.
e.g.
ListView.separated(
itemCount: 25,
separatorBuilder: (BuildContext context, int index) {
if (index % 5 == 0) { // Display `AdmobBanner` every 5 'separators'.
return AdmobBanner(
adUnitId: /* AdMob Unit ID */,
adSize: AdmobBannerSize.BANNER,
);
}
return Divider();
},
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text('item $index'),
);
},
)
This code is only an example, you might encounter Infinite Height layout errors as I am not aware of how admob_flutter
widgets operate.
However, this should be enough to get you started with your idea.
Let me know if this helped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With