load method

Future<bool> load({
  1. String? unitId,
  2. bool force = false,
  3. Duration? timeout,
  4. bool? nonPersonalizedAds,
  5. 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 _syncExecutor.exec(() async {
    return 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;
      },
    );
  }, null);
  if (isLoaded) lastLoadedTime = DateTime.now();
  return isLoaded;
}