load method
Future<bool>
load({
- String? unitId,
- bool force = false,
- Duration? timeout,
- bool? nonPersonalizedAds,
- List<
String> keywords = const [],
override
In order to show an ad, it needs to be loaded first. Use load()
to load.
To check if the ad is loaded, call interstitialAd.isLoaded
. You can't show()
an ad if it's not loaded.
For more info, read the documentation
If unitId
is null, MobileAds.interstitialAdUnitId
or
MobileAds.interstitialAdTestUnitId
is used
For more info, read the documentation
Implementation
Future<bool> load({
String? unitId,
bool force = false,
/// The timeout of this ad. If null, defaults to 1 minute
Duration? timeout,
/// Whether non-personalized ads should be enabled
bool? nonPersonalizedAds,
/// The keywords of the ad
List<String> keywords = const [],
}) async {
ensureAdNotDisposed();
assertMobileAdsIsInitialized();
if (!debugCheckAdWillReload(isAvailable, force)) return false;
isLoaded = (await channel.invokeMethod<bool>('loadAd', {
'unitId': unitId ??
this.unitId ??
MobileAds.interstitialAdUnitId ??
MobileAds.interstitialAdTestUnitId,
'nonPersonalizedAds': nonPersonalizedAds ?? this.nonPersonalizedAds,
'keywords': keywords,
}).timeout(
timeout ?? this.loadTimeout,
onTimeout: () {
if (!onEventController.isClosed && !isLoaded)
onEventController.add({
FullScreenAdEvent.loadFailed: AdError.timeoutError,
});
return false;
},
))!;
if (isLoaded) lastLoadedTime = DateTime.now();
return isLoaded;
}