void initState() {
// TODO: implement initState
bannerAd = BannerAd(
size: AdSize.banner,
adUnitId: AdMobService.bannerAdUnitId,
listener: BannerAdListener(
onAdLoaded: (_) {
setState(() {
_bstatus = true;
});
},
onAdFailedToLoad: (ad, err) {
print("failed to load banner$err");
ad.dispose();
},
),
request: new AdRequest());
bannerAd.load();
}
// code where it causes error
bottomNavigationBar: Container(
height: 50,
child: Stack(
children:[
Text("Ad space"),
if (_bstatus)
AdWidget(
ad: bannerAd,
key: UniqueKey(),
),
]
))
This is my code _bstatus is to check if banner is loaded or not. On starting an app it works fine but when ads get reload it give the below error
The following assertion was thrown building AdWidget-[#06603](dirty, state: _AdWidgetState#c9e02):
This AdWidget is already in the Widget tree
If you placed this AdWidget in a list, make sure you create a new instance in the builder function
with a unique ad object.
Make sure you are not using the same ad object in more than one AdWidget.
But if I do hot reload it works fine
How could I resolve it?