loadAd method
void
loadAd()
Implementation
void loadAd() {
if (_isLoading || _isLoaded || _adUnitId == null) return;
_isLoading = true;
_nativeAd = NativeAd(
adUnitId: _adUnitId!,
factoryId: 'listTile', // You need to implement this in platform code
request: const AdRequest(),
listener: NativeAdListener(
onAdLoaded: (ad) {
_isLoaded = true;
_isLoading = false;
onAdLoaded?.call('Native');
print('✅ Native Ad loaded successfully');
},
onAdFailedToLoad: (ad, error) {
_isLoaded = false;
_isLoading = false;
ad.dispose();
_nativeAd = null;
onAdError?.call('Native: ${error.message}');
print('❌ Native Ad failed to load: ${error.message}');
// Retry loading after delay
Future.delayed(AdConstants.adRetryDelay, () {
loadAd();
});
},
onAdOpened: (ad) {
onAdShown?.call('Native');
print('📱 Native Ad opened');
},
onAdClosed: (ad) {
onAdClosed?.call('Native');
print('🔒 Native Ad closed');
},
),
);
_nativeAd!.load();
}