After trying out the examples in other posts I am still stumped by this error. I have a list of 50 items and am showing an ad every 10. The first ad loads fine but others do not.
- I have 5 different ad IDs for Native ads to test for that
- I have wrapped the AdWidget in a StatefulBuilder (inside a generated list)
- I have even made a list of AdWidget calling each one only once
This is called for every 10th item in the list (an image is called otherwise)
return StatefulBuilder(builder: (context, setState) {
return Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(0)),
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Center(
child: isAdLoaded?SizedBox(
height: MediaQuery.of(context).size.width,
width: MediaQuery.of(context).size.width,
child: _adWidget[_cardData[index]],
):Column(
mainAxisSize: MainAxisSize.min,
children: const [
Icon(
Icons.help,
size: 64,
),
Text(
'There should have been an ad here but something went wrong\nPlease ignore and pardon the inconvenience',
textAlign: TextAlign.center,
)
],
),
),
);
});
This is also called at start in the initState (5 times)
void loadNativeAd(int d) {
_ad.add(
NativeAd(
adUnitId: adList[d],
factoryId: 'listTileMedium',
listener: NativeAdListener(
onAdLoaded: (ad) {
setState(() {
isAdLoaded = true;
});
},
onAdFailedToLoad: (ad, error) {
ad.dispose();
}
),
request: const AdRequest(),
),
);
_ad[d].load();
_adWidget.add(
AdWidget(
ad: _ad[d],
),
);
}