loadNativeAd static method

NativeAd loadNativeAd(
  1. String id, {
  2. void onLoaded()?,
})

Loads a NativeAd with the given id.

id is the ad unit ID. onLoaded is an optional callback executed when the ad loads successfully.

Returns a NativeAd that begins loading immediately.

Implementation

static NativeAd loadNativeAd(String id, {void Function()? onLoaded}) {
  return NativeAd(
    adUnitId: id,
    request: const AdRequest(),
    listener: NativeAdListener(
      onAdLoaded: (ad) {
        onLoaded?.call();
      },
      onAdFailedToLoad: (ad, error) {
        ad.dispose();
      },
      onAdOpened: (ad) => LoggerUtil.d('$NativeAd onAdOpened.'),
      onAdClosed: (ad) => LoggerUtil.d('$NativeAd onAdClosed.'),
    ),
    nativeTemplateStyle: NativeTemplateStyle(
      templateType: TemplateType.small,
      mainBackgroundColor: Colors.white12,
      callToActionTextStyle: NativeTemplateTextStyle(
        size: 16.0,
      ),
      primaryTextStyle: NativeTemplateTextStyle(
        textColor: Colors.black38,
        backgroundColor: Colors.white70,
      ),
    ),
  )..load();
}