admob-inline-ads-in-flutter icon indicating copy to clipboard operation
admob-inline-ads-in-flutter copied to clipboard

"This AdWidget is already in the Widget tree"

Open travelog-gypsy opened this issue 2 years ago • 0 comments

Getting "This AdWidget is already in the Widget tree".

Using below package: google_mobile_ads: ^1.0.1

minSdkVersion 23 targetSdkVersion 31

Widget nativeAdWidget() { AdsBloc ab = context.read<AdsBloc>(); return StatefulBuilder( builder: (context, setState) => Container( height: 72.0, alignment: Alignment.center, child: AdWidget(key: UniqueKey(), ad: ab.admobNativeAd), ), ); }

class AdsBloc extends ChangeNotifier { ..... void enableAds() { createAdmobNativeAd(); }

@override void dispose() { disposeAdmobNativeAd(); super.dispose(); }

createAdmobNativeAd() { _admobNativeAd = NativeAd( adUnitId: admobNativeAdId, factoryId: 'listTile', request: AdRequest(), listener: NativeAdListener( onAdLoaded: () { _admobNativeAdLoaded = true; }, onAdFailedToLoad: (ad, error) { ad.dispose(); print('Ad load failed (code=${error.code} message=${error.message})'); }, ), ); _admobNativeAd.load(); } ..... }

Please help me solve this issue!!!

travelog-gypsy avatar Mar 01 '22 05:03 travelog-gypsy