我试图在 a 中动态调用广告listview,但抛出此错误:
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.
Run Code Online (Sandbox Code Playgroud)
这是代码
导入包google_mobile_ads
import 'package:google_mobile_ads/google_mobile_ads.dart';
Run Code Online (Sandbox Code Playgroud)
然后实例化包
NativeAd _nativeAd;
final Completer<NativeAd> nativeAdCompleter = Completer<NativeAd>();
Run Code Online (Sandbox Code Playgroud)
我的功能是加载广告
loadAd(){
_nativeAd = NativeAd(
adUnitId: "ca-app-pub-3940256099942544/1044960115",
request: AdRequest(),
factoryId: 'adFactoryExample',
listener: AdListener(
onAdLoaded: (Ad ad) {
print('$NativeAd loaded.');
nativeAdCompleter.complete(ad as NativeAd); …Run Code Online (Sandbox Code Playgroud)