load method

Future<bool> load({
  1. String? unitId,
  2. bool force = false,
  3. Duration? timeout,
  4. bool? nonPersonalizedAds,
  5. List<String> keywords = const [],
  6. ServerSideVerificationOptions? serverSideVerificationOptions,
})
override

Load the ad. The ad must be loaded so it can be shown. You can verify if the ad is loaded calling rewardedAd.isLoaded

Usage:

(await rewardedAd.load());
if (rewardedAd.isLoaded) rewardedAd.show();

For more info, read the documentation

Implementation

Future<bool> load(
    {

    /// The ad unit id. If null, uses [MobileAds.rewardedAdUnitId]
    String? unitId,

    /// 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 should be enabled
    bool? nonPersonalizedAds,

    /// The keywords of the ad
    List<String> keywords = const [],

    ///SSV Info - Such as userId and customData
    ServerSideVerificationOptions? serverSideVerificationOptions}) async {
  ensureAdNotDisposed();
  assertMobileAdsIsInitialized();
  if (!debugCheckAdWillReload(isLoaded, force)) return false;
  isLoaded = (await channel.invokeMethod<bool>('loadAd', {
    'unitId': unitId ??
        this.unitId ??
        MobileAds.rewardedAdUnitId ??
        MobileAds.rewardedAdTestUnitId,
    'nonPersonalizedAds': nonPersonalizedAds ?? this.nonPersonalizedAds,
    'keywords': keywords,
    'ssv': serverSideVerificationOptions?.toJson()
  }).timeout(
    timeout ?? this.loadTimeout,
    onTimeout: () {
      if (!onEventController.isClosed && !isLoaded)
        onEventController.add({
          RewardedAdEvent.loadFailed: AdError.timeoutError,
        });
      return false;
    },
  ))!;
  if (isLoaded) lastLoadedTime = DateTime.now();
  return isLoaded;
}