admob-inline-ads-in-flutter
admob-inline-ads-in-flutter copied to clipboard
"This AdWidget is already in the Widget tree"
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!!!