load method

Future<bool> load({
  1. bool force = false,
  2. Duration? timeout,
})
override

Load the ad. The ad needs to be loaded to be rendered.

For more info, read the documentation

Implementation

Future<bool> load({
  /// 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,
}) async {
  ensureAdNotDisposed();
  assertMobileAdsIsInitialized();
  if (!debugCheckAdWillReload(isLoaded, force)) return false;
  isLoaded = (await channel.invokeMethod<bool>('loadAd').timeout(
    timeout ?? this.loadTimeout,
    onTimeout: () {
      if (!onEventController.isClosed && !isLoaded)
        onEventController.add({
          BannerAdEvent.loadFailed: AdError.timeoutError,
        });
      return false;
    },
  ))!;
  if (isLoaded) lastLoadedTime = DateTime.now();
  return isLoaded;
}