load method
Future<bool>
load({
- String? unitId,
- NativeAdOptions? options,
- bool force = false,
- Duration? timeout,
- bool? nonPersonalizedAds,
- List<
String> keywords = const [],
override
Load the ad. If the controller is disposed or the Mobile Ads SDK
(ADMOB SDK) is not initialized, an AssertionError
is thrown.
For more info, read the documentation
Implementation
Future<bool> load({
/// The ad unit id. If null, uses [MobileAds.nativeAdUnitId]
String? unitId,
NativeAdOptions? options,
/// Force to load an ad even if another is already avaiable
bool force = false,
/// The timeout of this ad. If null, defaults to 1 minute
Duration? timeout,
/// Whether non-personalized ads (ads that are not based on a user’s past behavior) should be enabled.
bool? nonPersonalizedAds,
/// {@macro ads.keywords}
List<String> keywords = const [],
}) async {
ensureAdNotDisposed();
assertMobileAdsIsInitialized();
if (!debugCheckAdWillReload(isLoaded, force)) return false;
unitId ??= MobileAds.nativeAdUnitId ?? MobileAds.nativeAdTestUnitId;
isLoaded = (await channel.invokeMethod<bool>('loadAd', {
'unitId': unitId,
'options': (options ?? NativeAdOptions()).toJson(),
'nonPersonalizedAds': nonPersonalizedAds ?? this.nonPersonalizedAds,
'keywords': keywords,
}).timeout(
timeout ?? this.loadTimeout,
onTimeout: () {
if (!onEventController.isClosed && !isLoaded)
onEventController.add({
NativeAdEvent.loadFailed: AdError.timeoutError,
});
return false;
},
))!;
if (isLoaded) lastLoadedTime = DateTime.now();
return isLoaded;
}