I recently started to code a 'social media' app. Tried to implement ads as Facebook does in its feed. I'm using a ListView.builder to create the feed and every n items built a new ad should be showed.
The problem is that it lag's for about half a second whenever you're scrolling close to an ad. I believe it is because of the listview.builder characteristic, which is that it builds the widgets just when they are to be shown in the screen.
I've already tested this in different cellphones in release. If I don't build ads, the feed scrolls perfectly smooth.
This is my initstate:
void initState() {
_banner = AdmobBanner(
adSize: AdmobBannerSize.MEDIUM_RECTANGLE,
adUnitId: Ads.bannerAd,
);
currentUser = authService.user;
_scrollController.addListener(() {
double maxScroll = _scrollController.position.maxScrollExtent;
double currentScroll = _scrollController.position.pixels;
double delta = MediaQuery.of(context).size.height * 0.25;
if (maxScroll - currentScroll < delta) {
firebaseService.obtenerMasDatos();
}
});
...
...
...
super.initState();
}
this is how I build the ads in the ListView.builder :
Container(
height: index % 8 == 0 ? 250 : 0,
child: index % 8 == 0 ? _banner : null,
)
Is there a different approach I could follow here?
Thank you very much.