load method
Future<bool>
load({
- String? unitId,
- bool force = false,
- Duration? timeout,
- bool? nonPersonalizedAds,
- List<
String> keywords = const [], - 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;
}