loadAd static method

BannerAd loadAd(
  1. String id, {
  2. void onLoaded()?,
})

Loads a BannerAd with the given id.

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

Returns a BannerAd that begins loading immediately.

Implementation

static BannerAd loadAd(String id, {void Function()? onLoaded}) {
  return BannerAd(
    adUnitId: id,
    request: const AdRequest(),
    size: AdSize.banner,
    listener: BannerAdListener(
      onAdLoaded: (ad) {
        onLoaded?.call();
      },
      onAdFailedToLoad: (ad, error) {
        LoggerUtil.e('BannerAd failed to load: $error');
        ad.dispose();
      },
    ),
  )..load();
}